Haskell IO :Не удалось сопоставить ожидаемый тип `IO a0' с фактическим типом

Я новичок в Haskell, и я пытаюсь понять, как правильно делать ввод-вывод.

Следующие работает нормально:

main = do
  action <- cmdParser
  putStrLn "Username to add to the password manager:"
  username <- getLine
  case action of
    Add -> persist entry
      where
        entry = Entry username "somepassword"

В то время как следующее приводит к ошибке компиляции:

main = do
  action <- cmdParser
  case action of
    Add -> persist entry
      where
        entry = Entry promptUsername "somepassword"

promptUsername = do
  putStrLn "Username to add to the password manager:"
  username <- getLine

Ошибка здесь:

Couldn't match expected type `IO b0' with actual type `[Char]'
Expected type: IO b0
  Actual type: String
In the expression: username
[...]

Что здесь происходит? Почему первая версия работает, а вторая нет?

Я знаю, что в Stack Overflow есть несколько подобных вопросов, но ни один из них не объяснил мне эту проблему.

6
задан Lauri Lehmijoki 18 August 2012 в 09:33
поделиться