从标准输入中解析和构造对象

readFloat::IO Float
readFloat =
    fmap read getLine

main::IO ()
main = do
    putStr "Type the first number: "
    first <- readFloat

    putStr "Type the second number: "
    second <- readFloat

    putStrLn $ show first ++ " + " ++ show second ++ " = " ++ show ( first + second )

输入:

Type the first number: 9.5
Type the second number: -2.02

输出:

9.5 + -2.02 = 7.48