[Haskell-cafe] and from standard Prelude

wren ng thornton wren at freegeek.org
Wed Aug 18 21:56:31 EDT 2010


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
> 
> Is there any reason for that besides some clever optimizations?


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?

-- 
Live well,
~wren


More information about the Haskell-Cafe mailing list