In my Haskell program, I want to read in a value given by the user using the getLine function. I then want to use the read function to convert thi
getLine
read
Here's an improved maybeRead which allows only for trailing whitespaces, but nothing else:
maybeRead
import Data.Maybe import Data.Char maybeRead2 :: Read a => String -> Maybe a maybeRead2 = fmap fst . listToMaybe . filter (null . dropWhile isSpace . snd) . reads