[Haskell-cafe] How the following works

Tsunkiet Man temp.tsun at gmail.com
Tue Apr 14 05:16:39 EDT 2009


Let's see, if I execute it by hand:

cinits :: [a] -> [[a]]
cinits [] = [[]]
cinits (x:xs) = [] : map (x:) (cinits xs)

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

Well, I understand this part. But isn't there an easier way to "see" the
answer?

Thank you for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090414/fee7686b/attachment.htm


More information about the Haskell-Cafe mailing list