[Haskell-cafe] Newbie question: mutually exclusive strict / lazy
Daniel Fischer
daniel.is.fischer at web.de
Sat Feb 9 11:56:34 EST 2008
Am Samstag, 9. Februar 2008 17:33 schrieb Peter Verswyvelen:
> Consider the function
>
> cond x y z = if x then y else z
>
> I guess we can certainly say cond is strict in x.
>
> But what about y and z?
>
> If x is true, then cond is strict in y
> If x is false, then cond is strict in z
>
> So we can't really say cond is lazy nor strict in its second or third
> argument.
>
> Of course, this is the case for many more functions, but in the case of
> the if-then-else primitive, does the strictness analyzer make use of this
> "mutually exclusive strictness" fact?
>
> Cheers,
> Peter
Hope I remember correctly...
A function is strict in an argument, if whenever that argument is _|_, the
result is _|_, regardless of possible other arguments.
Since
if True then 0 else _|_ == 0,
if-then-else is nonstrict in the third argument, similarly
if False then _|_ else 0 == 0,
so if-then-else is nonstrict in the second argument.
Cheers,
Daniel
More information about the Haskell-Cafe
mailing list