Simon Peyton-Jones wrote:
> > func n = map (func' n) [1..10]
> > func' x y = nfib x
> 
> There isn't a free subexpression to lift out of func.

No, but as Adrian Hey quite correctly points out there is
a free subexpression in func' that can be lifted out of
its enclosing (\y->...).

> Try this
> 
>         func n = map nfib [1..10]
> 
> Now the constant expression should be lifted out by GHC to give
> 
>         ans = map nfib [1..10]
>         func n = ans
> 

I have and it wasn't, the program I tried was as follows:

        main = do
         mapM print (map func ['a'..'z'])
         return ()

        func n = map nfib [1..10]

"map nfib [1..10]" was recomputed 26 times and not shared.

I have tried the same programs in a functional language 
implementation which lets you choose either lazy or fully lazy
evaluation and I get all the results I expect.

Mike



Reply via email to