"let" vs. "where" [was: Re: more unsafePerformIO questions (is it safe to use with ReadMode Handles)?]

Jan Scheffczyk jan@informatik.unibw-muenchen.de
Wed, 20 Aug 2003 07:42:59 +0200


Hi Andrew,

> 	let x = expensiveComputation foo in x + x
>
> I would certainly hope that expensiveComputation wasn't called twice,
> and even though the language doesn't guarantee it, I have already
> written code that assumed it.

I always thought that there is a tiny difference between "let" and "where":
Using "let" "expensiveComputation foo" might be computed twice (depending on 
the compiler?).
But using:

  x + x
  where x = expensiveComputation foo

should compute the value for x only once.
Therefore, I always try to use "where" for common subexpressions.

Please correct me if I'm wrong here.

Cheers,
Jan