Haskell: How to parse an IO input string into a Float (or Int or whatever)?

Viewed 25135

I am trying to make a program that takes a Float number inputted by the user via keyboard and does stuff with it.

However every time I try to parse the inputted String into a Float I keep getting errors. Every single method I've tried has failed to allow me to take user inputted data and turn it into a Float, which is what I need.

My practice program (not the actual problem I'm trying to solve) is:

main = do
    putStrLn "Please input a number."
    inputjar <- getLine
    read :: read a => String -> a
    putStrLn( read inputjar :: Int)

Edit

A further question.

How do I take the inputted string and turn it into something I can use in a calculation?

For example, how do I take the inputted string so that I can do something like:

(var + var) / 2
5 Answers
Related