Because it can lead to inconsistency. Imagine this code:
printName = do
print fullName
firstName <- getLine
lastName <- getLine
return ()
where
fullName = firstName ++ " " + lastName
This code does not work, and due to these situations, the use of related variables is limited to the part of the block dothat follows the actual binding. This becomes clear when the above code is discolored:
printName =
print fullName >>
getLine >>= (\ firstName ->
getLine >>= (\ lastName ->
return ()
)
)
where
fullName = firstName ++ " " ++ lastName
Here you can see that the variables firstNameand lastNameare not included in the scope of the proposal whereand that they can not be used in any of the definitions in this section.
source
share