[Haskell-cafe] Polymorphic algebraic type constructors
MR K P SCHUPKE
k.schupke at imperial.ac.uk
Tue Jun 22 08:50:30 EDT 2004
>(I still think it's a bug though:-)
It is definitely not a bug... you cannot assert that the types:
Either String a
Either String b
are both equal ant not equal at the same time. You either mean:
f :: (a->a) -> Either String a -> Either String a
Or you mean
f :: (a->b) -> Either String a -> Either String b
actually the second form a and b can be the same but they cannot
be unified inside the closure.
One way of doing this is to group all the string types on one side:
so instead of:
data A a = A a | B String | C String | D String
you do:
data A a = A a | B Strings
data Strings = S1 String | S2 String | S3 String
you can then write:
f :: (a->b) -> A a -> A b
f g (A a) = (A $ g a)
f g (B a) = (B a)
and use (S1 . B), (S2 . B), (S3 . B) to access each string.
Keean.
More information about the Haskell-Cafe
mailing list