[Haskell-cafe] polymorphic type
stefan at cs.uu.nl
Wed Jul 6 04:12:05 EDT 2005
> What I thought at first the signature of plus should be: plus :: (a ->
> c, b -> d) -> Either a b -> Either c d?Anyone know where I was wrong?
Your initial thought was right: it should
(a -> c, b -> d) -> Either a b -> Either c d
Why didn't you just test it by feeding in to a compiler or interpreter;
these are really useful, you know. ;)
> case :: (a -> c,b -> c) -> Either a b -> c
> case (f, g) (Left x) = f x
> case (f, g) (Right x) = g x
You can't name your function case: it's a reserved word.
You might want to check out the standard libraries:
case' = uncurry either
More information about the Haskell-Cafe