
19 May
2007
19 May
'07
2:46 p.m.
On 19/05/07, Andrew Coppin
Um... why doesn't this work?
my_fn x = do if x < 0 then do let y = 5 return () else do let y = 8 return ()
print y
(Error: "y" is not in scope.)
let-blocks only scope over the do-block they're contained in. Here y is out of scope once you leave the inner do-block. The solution is to do something like the following: do let y = if x < 0 then 5 else 8 print y -- -David House, dmhouse@gmail.com