[Haskell-cafe] Type parameters in type families

Hugo Pacheco hpacheco at gmail.com
Mon Mar 17 18:04:45 EDT 2008


Hi,

I am trying to understand some differences of parameterizing or not some
arguments of type families.
I have some code such as

*type family G a :: * -> *

instance Functor (G Int) where
   fmap f (Left ()) = Left ()
   fmap f (Right x) = Right (f x)

ggg :: Functor (G a) => G a x -> G a x
ggg = fmap id*

and it works fine.
However, I need to parameterize one extra argument (due to type equality):

*type family F a x :: *

class FunctorF d where
    fmapF :: (x -> y) -> F d x -> F d y

fff :: (FunctorF a) => F a b -> F a b
fff = fmapF id*

This second scenario fails to compile because the compiler cannot unify
types a and b with types d and x from the fmapF declaration.
Is there any other option than passing dummy variables to fmapF?
*
class FunctorF d where
    fmapF :: d -> x -> (x -> y) -> F d x -> F d y

fff :: (FunctorF a) => a -> b -> F a b -> F a b
fff a b = fmapF a b id*

Thanks,
hugo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080317/92a75221/attachment.htm


More information about the Haskell-Cafe mailing list