[Haskell-cafe] polymorphic type

Henning Thielemann lemming at henning-thielemann.de
Wed Jul 6 04:18:23 EDT 2005


On Wed, 6 Jul 2005, wenduan wrote:

> Dear all,
>
> Suppose we have defined two functions as below:
>
> case :: (a -> c,b -> c) -> Either a b -> c
> case (f, g) (Left x) = f x
> case (f, g) (Right x) = g x

It seems to be
  case == uncurry either

Prelude> :info either
-- either is a variable
either :: forall a c b. (a -> c) -> (b -> c) -> Either a b -> c

> plus :: (a -> b, c -> d) -> Either a b -> Either c d
> plus (f, g) = case(Left.f, Right.g)

> of plus should be:
>    plus :: (a -> c, b -> d) -> Either a b -> Either c d

That signature looks correct and it is accepted

Prelude> let plus = (\(f,g) -> uncurry either (Left . f, Right . g)) :: (a->c,b->d) -> Either a b -> Either c d



More information about the Haskell-Cafe mailing list