[Haskell-cafe] Combine list of sorted lists

Neil Mitchell ndmitchell at gmail.com
Fri Dec 29 14:32:05 EST 2006


Hi Quan


> 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"

The final f3 clause can be made a bit neater:

> f3 la@(a:as) lb@(b:bs) | sum a <= sum b = a : f3 as lb
                                    | otherwise = b : f3 la bs

Additionally, if it was me I'd refer to a:as on the RHS, rather than
giving it a name with the @ pattern, but thats a personal question of
style.

Thanks

Neil


More information about the Haskell-Cafe mailing list