I have this:
data SomeData = SomeData Int Int
getDataFromUser :: SomeData
getDataFromUser = do
{
read (getLine)::SomeData;
}
This doesnt compile : Expected type String Actual type IO String
How I can fix it? I need this data deserialization…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re trying to treat
getLineas a String, but it’s anIO String— an IO action that, when executed, produces a string. You can execute it and get the resulting value from inside adoblock by using<-, but sincegetDataFromUserdoes IO, its type has to beIO SomeData:More broadly, I would recommend reading a tutorial on IO in Haskell, like Learn You a Haskell’s chapter on IO; it’s very different from the IO facilities of most other languages, and it can take some time to get used to how things fit together; it’s hard to convey a full understanding with answers to specific questions like this 🙂