On Wed, Aug 18, 2010 at 9:56 PM, wren ng thornton <w...@freegeek.org> wrote: > Oleg Lobachev wrote: >>> >>> #ifdef USE_REPORT_PRELUDE >>> and = foldr (&&) True >>> or = foldr (||) False >>> #else >>> and [] = True >>> and (x:xs) = x && and xs >>> or [] = False >>> or (x:xs) = x || or xs >>> >>> {-# RULES >>> >>> "and/build" forall (g::forall b.(Bool->b->b)->b->b) . >>> and (build g) = g (&&) True >>> >>> "or/build" forall (g::forall b.(Bool->b->b)->b->b) . >>> or (build g) = g (||) False >>> >>> #-} >>> #endif >>> > The thing I find puzzling is that the foldr is inlined. The (regular) clever > optimizations for build/foldr seem like they should already handle this > without the need for the extra rules. I wonder how much is gained by > specializing to (&&)/True instead of relying on the regular deforestation?
The above code does not inline and / or, *unless they are fused using the RULES.* There's not really any benefit to inlining them otherwise, and it duplicates code. -Jan-Willem Maessen > > -- > Live well, > ~wren > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe