Hacker News new | ask | show | jobs
by zokier 3498 days ago
I'm not sure I get what's the difference between for example:

    def filterFilterTest (xs : Rep[Array[Int]]) : Rep[Int] =
        Stream[Int](xs)
          .filter(d => d % 2 == 0)
          .filter(d => d % 3 == 0)
          .fold(unit(0), ((a : Rep[Int]) => (b : Rep[Int]) => a + b))
and

    xs.filter(d => d % 2 == 0).filter(d => d % 3 == 0).fold(0)(_+_)
(grabbed from unit tests here: https://github.com/strymonas/staged-streams.scala/blob/maste... )

They both look pretty much the same and superficially do the same thing too, so what makes this new thing better/novel?

1 comments

I would say that the latter is non-optimal, i.e. generates some unnecessary intermediary values whereas the former is optimal as shown in the paper.