f1 f g xs = map f (map g xs) -- each element will be f(g(x))
f2 f g xs = map (f.g) xs
f3 xs = map (\x -> (x+1)/2) xs
f4 xs = map ((/2).(+1)) xs
f5 xs = map (/2) (map (+1) xs)
----- test -----
main = do
putStrLn $ show $ f1 (*3) (+2) [1..10]
putStrLn $ show $ f2 (*3) (+2) [1..10]
putStrLn $ show $ f3 [1..10]
putStrLn $ show $ f4 [1..10]
putStrLn $ show $ f5 [1..10]
This entry was posted
on Wednesday, June 6th, 2007 at 3:25 pm and is filed under Haskell - SOE.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.