[Haskell-cafe] lifting restrictions on defining instances

John Lask jvlask at hotmail.com
Fri Jul 17 20:56:11 EDT 2009

Can anyone explain the theoretical reason for this limitation, ie other than 
it is a syntactical restriction, what would it take to lift this restriction 

----- Original Message ----- 
From: "Stefan Holdermans" <stefan at cs.uu.nl>
To: "Petr Pudlak" <deb at pudlak.name>
Cc: <haskell-cafe at haskell.org>
Sent: Saturday, July 18, 2009 5:25 AM
Subject: Re: [Haskell-cafe] an instance in other than the last type 

> Petr,
>> If I want to make it a functor in the last type variable (b), I can  just 
>> define
>>> instance Functor (X a) where
>>>  fmap f (X a b) = X a (f b)
>> But how do I write it if I want X to be a functor in its first type 
>> variable?
> Short answer: you can't. Easiest way to workaround is to define a  newtype 
> wrapper around your original datatype:
> newtype X' b a = X' {unX' :: X a b}
> instance Functor (X' b) where
>   fmap g (X' (X a b)) = X' (X b (g a))
> Cheers,
>   Stefan
> _______________________________________________
> 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