[Haskell-cafe] ghc has problems with 'zipWith' ?

Tom Pledger tpledger at ihug.co.nz
Wed Dec 8 04:38:00 EST 2004


Daniel Fischer wrote:

>Hi,
>I have recently come across the curious phenomenon that ghci is sometimes much 
>slower than hugs.
>
[...]

>ms as = zipWith (+) (zipWith (*) as (1:ms as)) (0:1:ms as)
>

Hugs has(**) a specific optimisation for the case where the left hand 
side of the declaration occurs as a subexpression in the right hand side.

You can get a similar benefit under ghci if you share the common 
subexpression by hand:

    ms' as = let bs = ms' as in
             zipWith (+) (zipWith (*) as (1:bs)) (0:1:bs)

(**) I haven't actually seen the code in question, and am repeating 
something which was on one of the mailing lists a few years ago. So 
please don't treat this as authoritative!

Regards,
Tom




More information about the Haskell-Cafe mailing list