[Haskell-beginners] scope for variables
legajid at free.fr
Wed Dec 9 16:40:51 EST 2009
i wrote the following (very simplified) program :
word :: [Char]
myloop = do
myloop2 = do
main = do
putStrLn "Enter the word"
word <- enter_word
"word" is initially binded to the value "initial"
myloop, calling myloop2, displays this value
"Improving" my program, i add "main" that enters a new value for "word"
(here a fix one, ideally a getLine)
To display this new value, i must call myloop with this parameter, which
is then passed to myloop2.
Is there a way to make a "global binding ?", thus changing the value of
"word", so that i don't have to modify the code for myloop and myloop2
(now being passed a parameter), that worked fine. This would make the
program modular and easy to modify, without modifying all existing
functions. Or is it non-sense in Haskell ?
More information about the Beginners