
22 Dec
2005
22 Dec
'05
9:27 p.m.
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) = ...