[Haskell-cafe] Combine list of sorted lists
Bryan Burgers
bryan.burgers at gmail.com
Fri Dec 29 14:48:45 EST 2006
> > I am not sure how to express f1 with map? how do I say
> > (lambda (ls)
> > (map (lambda (x) (list x))
> > ls))
> > in Haskell? map ([]) ?
>
> map (:[]), :[] takes a single element and puts it into a list. Some
> people refer to this as "box"
Another way to express f1 with map is:
f1 xs = map (\x -> [x]) xs
The (\x -> [x]) is a lambda that takes an x and puts it in a list.
This is semantically the same as (\x -> x:[]), where (:) puts x at the
front of the empty list ([]). So, this is where Niel gets his method
(:[]) -- ie, just like (\x -> x+1) is semantically the same as (+1),
so (\x -> x:[]) is semantically the same as (:[]).
Bryan
More information about the Haskell-Cafe
mailing list