[Haskell-cafe] Polymorphic algebraic type constructors

Adrian Hey ahey at iee.org
Tue Jun 22 08:38:58 EDT 2004


I think this was the topic of my very first post to Haskell
mailing list, many years ago..

 http://www.dcs.gla.ac.uk/mail-www/haskell/msg00452.html

I think the answer is no. Apparently this is feature
(I still think it's a bug though:-)

Regards
--
Adrian Hey

On Monday 21 Jun 2004 6:03 pm, Graham Klyne wrote:
> If I have a polymorphic algebraic type (T a) with several type
> constructors, only one of which actually references the type parameter, is
> there any way to express type conversion for the type-parameter-independent
> constructors without actually mentioning all the constructors?
>
> Here's a simple example based on Either:
>
> [[
> data A = A String deriving (Show, Eq)
> data B = B String deriving (Show, Eq)
>
> f :: (a->b) -> Either String a -> Either String b
> f g (Right a) = (Right $ g a)
> f g (Left  s) = (Left s)
> -- f g (s) = (s) -- doesn't work
>
> a2b (A s) = (B s)
>
> t1 = f a2b (Left "x")
> t2 = f a2b (Right (A "y"))
> ]]
>
> The second case for 'f' throws a type error when the constructor 'Left' is
> omitted, because the type of 's' is fixed to be Either String A when the
> required result (in this case, because of a2b) is Either String B.
>
> #g
>
>
> ------------
> Graham Klyne
> For email:
> http://www.ninebynine.org/#Contact
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list