[Haskell-cafe] tuple and HList
zednenem at psualum.com
Mon Mar 21 19:17:40 EST 2005
Frederik Eaton writes:
> > You need to swap the arguments to TCons...
> > data TCons l a = TCons !l a
> > Then:
> > instance Functor (TCons (TCons HNil a)) where
> > fmap f (TCons (TCons HNil x) y) = TCons (TCons HNil (f x)) y)
> How does one solve this problem in general, i.e. when the arguments to
> a type are in the wrong order for an instance that one wants to
In general? You either make a newtype or change the definition of the
> Someone on the haskell IRC channel mentioned that if you could derive
> instances for partially applied type synonyms then one could just
> make a dummy synonym with the arguments in the right order, but that
> doesn't appear to be premitted. The other question is why isn't it
As I understand it, the reason you can't do instances for partially
applied type synonyms is because it makes instance selection ambiguous.
instance Functor ((,) a) where fmap f (x,y) = (x, f y)
type RevPair a b = (b,a)
instance Functor (RevPair a) where fmap f (x,y) = (f x, y)
If I write 'fmap f (x,y)', do I get '(f x, y)' or '(x, f y)'?
David Menendez <zednenem at psualum.com> <http://www.eyrie.org/~zednenem/>
More information about the Haskell-Cafe