[Haskell-beginners] Map on Nested Lists

Deniz Dogan deniz.a.m.dogan at gmail.com
Thu Apr 8 09:41:03 EDT 2010


2010/4/8 Ben Derrett <ben.derrett at googlemail.com>:
> Hi,
> I'm trying to write a generalization of the map function that operates on
> nested lists, e.g. [[a]] or [[[a]]]. (It should map all elements of type a
> (not list) with f)
> I was thinking of something along these lines:
> mapN f *list of type [a] (where a is not a list type)* = map f l
> mapN f l = (mapN f (head l)):(mapN f (tail l))
>
> Any suggestions about how to go about this?
> Many thanks,
> Ben
>

I think you should look into generic programming for doing this, e.g.
"Scrap Your Boilerplate". There are (at least) three papers on it[1].

[1]: http://research.microsoft.com/en-us/um/people/simonpj/Papers/hmap/index.htm

-- 
Deniz Dogan


More information about the Beginners mailing list