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
from mathematics. From memory I think a `mod` b * c is an example. This caused some complaints and was quietly dropped. For let/where, my recollection is that the issue was raised and the solution agreed on the same day at one of the Glasgow meetings in '88. After that it was outside the domain

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