[Haskell-beginners] Mutable variables in do block?

Emanuel Koczwara poczta at emanuelkoczwara.pl
Sun Feb 24 11:41:00 CET 2013


1 main = do
2  line <- getLine
3  putStrLn line
4  line <- getLine
5  putStrLn line

Here I have 'line' first bounded with a value at line 2, and then at
line 4. It looks like I can set (or bind) a variable in 'do' block more
than once, and it looks like it's a destructive update.

But as I'm thinking about this more and more, it appears that the first
and second 'line' are just an ordinary immutable variables. Line 4 just
hides the 'line' from line 2 (outer lambda). Am I right?


More information about the Beginners mailing list