why doesn't this work


#1
f :: (Either Int  , Maybe Int) -> Int         
f = \t -> case t of
  
  (Right(x) , Just(y)) -> x + y
  (Left(x) , Just(y)) -> x 
  (x , Nothing ) -> 0

-- Aufgabe 2.2 b)
g :: (Integer , Integer ) -> Integer               
g = \t -> case t of
 (x , y ) 
 | x + z > 100 -> x + y
 | odd(x) * y <= 100 -> x - y
 | otherwise -> x * y 

#2

There are a number of errors; but it’s hard to tell without knowing what problem you are trying to solve. From taking a quick glance:

  • Either Int in the signature of f takes another parameter; it’s either an Int or …
  • odd(x) * y does not work: odd will return a Bool, which you cannot multiply with an Integer

But again, it would be better to ask more specific questions if you’re struggling to understand a certain part.


#3

Function application in Haskell doesn’t require parenthesis as you seem to be doing for Left, Right, Just.

Parenthesis are used to define priority of associativity of terms, or to express tuples

f :: (a, b) -> c --takes a tuple of an a and b to return a c

---your matches should look like
(Right x, Just y) -> x + y
(Left x, Just y)  -> x
(_ , Nothing)     -> 0 
-- note that, since we don't use the either value, we can avoid adding a name for it, and 
-- use the empty placeholder '_'