user266003
user266003

Reputation:

Trying to deal with IO actions

I'm trying to deal with IO actions. I wonder why does this work:

main = do
  alias = getLine
  name <- alias
  putStrLn ("your name is: " ++ name)

saying

 parse error on input `='

Upvotes: 2

Views: 121

Answers (1)

Sergey Sosnin
Sergey Sosnin

Reputation: 1403

Add keyword let

main = do
  let alias = getLine
  name <- alias
  putStrLn ("your name is: " ++ name)

do is a specified construction for monadic bind operator, it's not a cosmic space. All you write into block do is really chain of >>= monaidic functions. So you should use let construction. But you can make alias in other part of you program.

alias = getLine

main = do
  name <- alias
  putStrLn ("your name is: " ++ name)

Upvotes: 9

Related Questions