[Haskell-cafe] tuple and HList

Keean Schupke k.schupke at imperial.ac.uk
Mon Mar 21 04:09:37 EST 2005


David Menendez wrote:

>
>    instance Functor ((,) a) where
>        fmap f (x,y) = (x, f y)
>  
>

>If we get rid of '(,)' and redefine '(a,b)' as sugar for 'TCons a (TCons
>b HNil)' (or whatever), then there is no way to declare the above instance.                             I don't think that's a deal-killer, but it is a disadvantage.
>  
>

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)

    Keean.



More information about the Haskell-Cafe mailing list