[Haskell-cafe] let vs. where

Neil Mitchell ndmitchell at gmail.com
Tue Nov 13 16:22:24 EST 2007


> Maybe it would be enough to represent the example "where" problem more
> fairly on its own terms.  The non-working example has us writing
>   f = State $ \ x -> y
>      where y = ... x ...

I just don't think this example is representative of the typical
decisions in the trade-off. There are reasons to use let, and reasons
to use where, but refactoring the entire code into a state monad isn't
one I would have ever come up with!

A more balanced variant of the page could mention this as one
particular case where a let might be preferred, but the fundamental
question of let vs where should deal with things like expression vs
statement, scoping, textual ordering, strictness, pattern matching,
desugaring etc - but probably mainly focus on "style".

My personal view is to nearly always use a where, except in a monad,
where a do-let is correct choice. I very occasionally use a let-in,
but only for reasons of textual ordering.



More information about the Haskell-Cafe mailing list