let/where

2001-09-19 Thread Mark Carroll
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

Re: let/where

2001-09-19 Thread Ian Lynagh
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

Re: let/where

2001-09-19 Thread Olaf Chitil
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.

Re: let/where

2001-09-19 Thread John Hughes
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

Re: let/where

2001-09-19 Thread Brian Boutel
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

Re: let/where

2001-09-19 Thread Mark Carroll
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