從標準輸入中解析和構造物件

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