I'm rather new to Haskell, and I'm currently using LearnYouAHaskell. I am trying to take a string separated by white space, and break it into a list of smaller word strings. My current program:
main = do
putStrLn "Insert a string to convert: "
-- Input string
line <- getLine
words line;
But in this case, it tells me I'm having an IO error. TO my understanding, getLine is an action, and so since this is impure, I have to bind it to "line". Line is an accurate representation of getLine, which is an IO String.
However, shouldn't line be a string? When I try to use words on line, it tells me "Couldn't match expected type "IO a0" with actual type [String]
As if line isn't a string. Furthermore, can I use :t line in the program itself when I make it to see if it's actual of the right type or not?
I apologize for the novice question, but I'm a bit stuck.
EDIT:
I did something similar in GHCI, and it tells me that my type is in fact a normal string.. I don't get it.
Prelude> line <- getLine
"Hello fellows"
Prelude> :t line
line :: String
Prelude> words line
["Hello","fellows"]
Why doesn't that work?
words linehas type[String], but all statements in the do block are expected to have typeIO a0for some typea0.