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
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 Intin the signature of
ftakes another parameter; it’s either an
odd(x) * ydoes not work:
oddwill return a
Bool, which you cannot multiply with an
But again, it would be better to ask more specific questions if you’re struggling to understand a certain part.
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 '_'