[Haskell-cafe] fmap for lists of lists of lists of ...

Greg Buchholz haskell at sleepingsquirrel.org
Tue Mar 14 22:40:24 EST 2006


    Is it possible to make a typeclass like Functor, that has a function
(say "f_map"), which would work for the infinite hierarchy of types:
([],[[]],[[[]]],...)?  Does that make sense?  This doesn't work...

>class Funct f where
>    f_map :: (a -> b) -> f a -> f b
>
>instance Funct [] where
>    f_map = map
>
>instance Funct a => Funct [a] where
>    f_map f = map (f_map f)
>
>main = print $ fmap (+1) [[[1,2,3]]]

...but maybe it gets the idea across?


Thanks,

Greg Buchholz



More information about the Haskell-Cafe mailing list