[Haskell-cafe] How the following works

Lennart Augustsson lennart at augustsson.net
Tue Apr 14 05:32:02 EDT 2009


map f xs = [ f x | x <- xs ]

On Tue, Apr 14, 2009 at 11:21 AM, Tsunkiet Man <temp.tsun at gmail.com> wrote:
> Let's see...
>
> cinits [] = [[]]
> cinits (hd:tl) = [] : [ hd : rest | rest  <- cinits tl ]
>
> Well, ehm, I'm trying to understand "map" in "map" functions, however I do
> understand list comprehensions. But I don't think I can write "any" "map" in
> "map" function into a list comprehension can I?
>
> 2009/4/14 Daniel Fischer <daniel.is.fischer at web.de>
>>
>> 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
>>
>
>
> _______________________________________________
> 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