[Haskell-cafe] A probably-stupid question about a Prelude implementation.

Chris Kuklewicz haskell at list.mightyreason.com
Fri Jun 22 11:52:24 EDT 2007


Neil Mitchell wrote:
> Hi Michael,
> 
> You're wrong :)
> 
>  > foldr (||) False (repeat True)
> 
> Gives:
> 
>  > True
> 
> Remember that in Haskell everything is lazy, which means that the || 
> short-circuits as soon as it can.
> 
> Thanks
> 
> Neil
> 

Specifically it is graph reduced like this:

or [F,T,F,F...]

foldr (||) F [F,T,F,F...]

F || foldr (||) F [T,F,F...]

foldr (||) F [T,F,F...]

T || foldr (||) F [F,F...]

T

The last line is because (T || _ = T) and lazyness



More information about the Haskell-Cafe mailing list