[Haskell] factoring `if'
Colin Runciman
colin at cs.york.ac.uk
Mon Oct 11 06:30:50 EDT 2004
Serge,
>How do you think, is the program (1) equivalent to (2)
>in the meaning of Haskell-98 ?
>
>(1) (\ x -> (if p x then foo (g x) else foo (h x))
> where
> p ... g ... h ... foo ...
> )
>
>(2) (\ x -> foo ((if p x then g x else h x)
> where
> p ... g ... h ... foo ...
> )
> )
>
>
Both examples are illegal -- there are no where-expressions in Haskell,
only where-equations.
Ignoring the local definition part, however, the answer is no. Lifting
foo out of the branches of the conditional is only valid if foo is strict.
Colin R
More information about the Glasgow-haskell-users
mailing list