
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

Wenduan,
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. ;) Besides...
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 HTH, Stefan

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
participants (3)
-
Henning Thielemann
-
Stefan Holdermans
-
wenduan