
29 Dec
2006
29 Dec
'06
2:48 p.m.
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