There seem to be a few situations where it's not clear to me when to use
let and when where. For instance, in this little example I was playing
with to work out what syntax works,
main = putStr (show (if maybe_index == Nothing then DP_Unknown else DP_Number index)
++ \n)
where
On Wed, Sep 19, 2001 at 01:53:22PM -0400, Mark Carroll wrote:
main = let maybe_index = maybe_read word
in putStr (show (if maybe_index == Nothing then DP_Unknown else DP_Number
index) ++ \n)
where (Just index) = maybe_index
BTW, is the above a sane way of getting the
Yes, Haskell is a rather big language and unfortunately has much
redundancy. It seems mostly to be a matter of taste which of `let' and
`where' you prefer. Personally, I nearly always use `where' when
possible (for the same reason you give); `let' only if the `where' would
be too far away.
The point of where is that it scopes over guards and multiple equations as
well as right hand sides.
f x | xsquared 1000 = xsquared
| otherwise = 0
where xsquared = x*x
For the same reason, it has to be restricted to appear at the top level of a
right hand
Norman Ramsey wrote:
Was it not considered to forbid such ambiguous expressions, requiring
explicit parentheses to resolve the ambiguity?
Yes. At one time some expressions using infix operators at the same
precedence had to be parenthesised if there was no natural
associativity familiar
Thanks very much everyone, especially for the notes about the differences
between let and where, and the uses of case and maybe! Someday it
would be interesting to try a programming assignment and comparing my
coding style with the useful idioms that everyone else uses to see how
much I still