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

Henning Thielemann iakd0 at clusterf.urz.uni-halle.de
Wed Dec 8 07:50:09 EST 2004


On Wed, 8 Dec 2004, Daniel Fischer wrote:

> Am Mittwoch, 8. Dezember 2004 10:22 schrieben Sie:
> > On Tue, Dec 07, 2004 at 06:44:33PM +0100, Daniel Fischer wrote:
> > > ms :: [Integer] -> [Integer]
> > > ms as = zipWith (+) (zipWith (*) as (1:ms as)) (0:1:ms as)
> >
> > This version seems to be faster, but I don't know if it addresses your
> > concern:
> >
> >   ms as = let l = zipWith (+) (zipWith (*) as (1:l)) (0:1:l) in l
> >
> > Best regards,
> > Tomasz
> 
> Thanks,
> indeed, this seems to produce roughly the same performance as 'ps' and I have 
> a vague idea why this is better than 'pms', given that 'ms' is slower than 
> 'ps'. But that is what baffled me in the first place, particularly because in 
> hugs, things are different.

Is it possible and senseful for a compiler to extract common
sub-expressions? Naively I think that for a given tree of an expression it
is efficiently possible to find all common sub-trees. Referential
transparency would assure that equal expressions have the same value, so
they can be replaced by the same object. E.g.  the example above could be
automatically transformed to: 

ms as =
   let tmp0 = zipWith (+) (zipWith (*) as tmp1) (0:tmp1)
       tmp1 = 1:tmp0
   in  tmp0



More information about the Haskell-Cafe mailing list