[Haskell-cafe] and from standard Prelude

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Wed Aug 18 05:10:49 EDT 2010


Oleg Lobachev <lobachev at Mathematik.Uni-Marburg.de> writes:

>> #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? I am
> particularly interested in the behavior of and for infinite lists and
> these two versions are equivalent in this aspect.

Precisely for clever optimisations.  See the paper "A Short Cut to
Deforestation" by Andrew Gill, John Launchbury and Simon Peyton Jones
(from 1993 apparently; I'm going off a copy I have locally).

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list