
12 Jan
2009
12 Jan
'09
9:58 a.m.
On Mon, 12 Jan 2009, Neil Mitchell wrote:
Hi
No because the current definition are recursive and ghc cannot inline recursive functions.
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 ...
HLint would probably just suggest you use a supercompiler*, for which specialisation such as this is easy (http://www.cs.york.ac.uk/~ndm/supero). HLint is about making code prettier,
Actually, I find the 'go' variant prettier, because it clearly shows that the 'f' is not "altered" in the recursion.