
12 Jan
2009
12 Jan
'09
9:06 a.m.
On Mon, 12 Jan 2009, Duncan Coutts wrote:
On Mon, 2009-01-12 at 01:02 +0100, Lennart Augustsson wrote:
Does GHC specialize map? If it doesn't, then hand crafted version could be faster.
No because the current definition are recursive and ghc cannot inline recursive functions.
map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs
It has to be manually transformed into a version that is not recursive at the top level:
map :: (a -> b) -> [a] -> [b] map f = go where go [] = [] go (x:xs) = f x : go xs
Then the map can be inlined at the call site and the 'f' inlined into the body of 'go'.
Maybe HLint can make such suggestions ...