What is the scope of a bound variable? Why can’t I access it from within where clause?
For instance, in this example:
someFunc x y = do
let a = x + 10
b <- someAction y
return subFunc
where
subFunc = (a * 2) + (b * 3)
Here, the subFunc can see a but not b.
Why can’t I use bound variable within where clause? Thank you.
Because it could lead to inconsistencies. Imagine this code:
This code wouldn’t work, and because of these kinds of situations, the use of bound variables is limited to the part of a
doblock that follows the actual binding. This becomes clear when desugaring the above code:Here, one can see that the variables
firstNameandlastNameare not in scope in thewhereclause, and that they cannot be used in any definitions in that clause.