[Haskell-cafe] ANN: HLint 1.2
Jan-Willem Maessen
jmaessen at alum.mit.edu
Mon Jan 12 10:49:06 EST 2009
On Jan 12, 2009, at 9:01 AM, Duncan Coutts wrote:
> 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'.
This seems like exactly the sort of mechanical transformation that
computers do quickly and accurately, and humans get wrong. Surely it
wouldn't be that hard for GHC to transform self recursion in this way
(possibly subject to the condition that the result be worth inlining)?
[phc did this, and I think it was inherited from Lennart's program
transformations.]
-Jan-Willem Maessen
More information about the Haskell-Cafe
mailing list