[Haskell-cafe] polymorphic type
wenduan
xuwenduan2010 at gmail.com
Tue Jul 5 15:52:49 EDT 2005
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
plus :: (a -> b, c -> d) -> Either a b -> Either c d
plus (f, g) = case(Left.f, Right.g)
My question is regarding to the function signature of 'plus' , in its
signature, does the 'a' in 'a -> b' and in 'Either a b', must be
instantiated to the same object when the function is applied?E.g.,Either
a b is instantiated to 'Either Char b', will the 'a' in 'a -> b' be
instantiated to 'Either Char b'?Furthermore, are the two bs in 'a -> b'
and 'Either a b' not conflicting?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?
--
X.W.D
More information about the Haskell-Cafe
mailing list