factoring `if'

Carsten Schultz carsten at codimi.de
Mon Oct 11 06:34:05 EDT 2004


Hi!

On Mon, Oct 11, 2004 at 02:19:45PM +0400, Serge D. Mechveliani wrote:
> Dear Haskell implementors,
> 
> 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 ...
>                    )
>       )

In general they are not, for exactly the reason you give:

> The reason for this may be, for example, that the result printing
> of  (f x)  is more `lazy' in (2) than in (1):
> the part of  foo  may print immediately and  (g x) or (h x)  may print
> long after.
> This is a difference in behavior, it does not effect the computation
> meaning.

If  p x == _|_  and  foo _|_ /= _|_, then (1) does not equal (2).

> I have a large program which is easily written in the style of (1),
> (and in many places it sets `case' instead of `if').  
> Annoyingly, it prints out in a not a lazy manner.

You get what you specify :-)

Greetings,

Carsten

-- 
Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin
http://carsten.codimi.de/
PGP/GPG key on the pgp.net key servers, 
fingerprint on my home page.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/glasgow-haskell-users/attachments/20041011/ebda0158/attachment.bin


More information about the Glasgow-haskell-users mailing list