[Haskell-cafe] Re: kinds question

Ashley Yakeley ashley at semantic.org
Thu Dec 22 21:27:41 EST 2005


David Roundy wrote:
> Hello all,
> 
> I have a question about how to create the right kind to declare lists to be
> a class.  I have a class Foo
> 
> class Foo f where
>   foo :: f a -> Foo
> 
> and I want to define that a list of Foos is also a Foo, but can't see how
> to do it.  I imagine something like
> 
> instance Foo f => Foo [f] where
>   foo xs = map foo xs
> 
> but of course [f] isn't a valid type.

[] and f both have * -> *, and you want to compose them. You can do this 
like this:

   newtype Compose p q a = MkCompose p (q a)

and then

   instance Foo f => instance (Compose [] f) where
     foo (MkCompose fs) = ...



More information about the Haskell-Cafe mailing list