[Haskell-cafe] How the following works

Lennart Augustsson lennart at augustsson.net
Tue Apr 14 04:52:30 EDT 2009


Why don't you hand execute it on an example, like cinits [1,2,3]?

cinits [1,2,3] = cinits (1:2:3:[]) =
[] : map (1:) (cinits (2:3:[]) =
[] : map (1:) ([] : map (2:) (cinits (3:[])) =
...


On Tue, Apr 14, 2009 at 10:39 AM, Tsunkiet Man <temp.tsun at gmail.com> wrote:
> 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?
>
> (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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list