Talk:Yet Another Haskell Tutorial/Language advanced/Solutions

Haskell newb, here. Here were my answers to the Partial Application exercises. -- Exercise 7.1 Convert the following functions into point-free style, if possible. func1 x l = map (\y -> y*x) l func2 f g l = filter f (map g l) func3 f l = l ++ map f l func4 l = map (\y -> y+2) (filter (\z -> z `elem` [1..10])                      (5:l)) func5 f l = foldr (\x y -> f (y,x)) 0 l

-- Answers: func12 x = map (*x)                                 -- definitely better func22 f g = filter f. map g                       -- debatably better.. func32 l = (l++). (`map` l)                        -- not really better? func42 = map (+ 2). filter (`elem` [1..10]). (5:) -- shorter, and probably better func52 f = foldr uncurry f 0                        -- better

The function

func3 f l = l ++ map f l

can also be written as...

func32 l = (l++). (`map` l)

It's ugly, and longer, but it does have free-point style, does it not?

-- Chris (talk) 23:49, 14 December 2007 (UTC)

The function

func5 f l = foldr (\x y -> f (y,x)) 0 l

also can be written as...

func52 = flip foldr 0. curry

points for being completely point-free. -- Glen (talk)