[Haskell-cafe] How the following works
Lennart Augustsson
lennart at augustsson.net
Tue Apr 14 05:31:35 EDT 2009
Assuming you already think you know what cinits does, you can convince
yourself using induction.
On Tue, Apr 14, 2009 at 11:16 AM, Tsunkiet Man <temp.tsun at gmail.com> wrote:
> 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!
> _______________________________________________
> 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