[Haskell-cafe] How the following works

Daniel Fischer daniel.is.fischer at web.de
Tue Apr 14 05:00:34 EDT 2009


Am Dienstag 14 April 2009 10:39:28 schrieb Tsunkiet Man:
> Hello,
>
> I can hardly imagine how the following code works:
>
> cinits :: [a] -> [[a]]
> cinits [] = [[]]
> cinits (x:xs) = [] : map (x:) (cinits xs)
>
> can someone give me a good explaination?

Perhaps it's easier to follow as a list comprehension:

cinits [] = [[]]
cinits (hd:tl) = [] : [ hd : rest | rest  <- cinits tl ]

>
> (I understand it a bit, but it's really hard for me to figure out how a map
> in a map function works.)
>
> Thank you for your time,
>
> Tsunkiet



More information about the Haskell-Cafe mailing list