[Haskell-cafe] Combine list of sorted lists

David House dmhouse at gmail.com
Fri Dec 29 14:47:05 EST 2006


Sorry to Neil for multiple copies.

On 29/12/06, Neil Mitchell <ndmitchell at gmail.com> wrote:
> > 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"

You can pretty much directly translate your Lisp:

\ls -> map (\x -> [x]) ls

Which eta-reduces to:

map (\x -> [x])

Now the inner lambda can be written as:

\x -> x : []

Or,

(: [])

That's a section on the ':' operator. So the whole thing becomes:

map (:[])

Hope that helps.

-- 
-David House, dmhouse at gmail.com


More information about the Haskell-Cafe mailing list