
17 Dec
2010
17 Dec
'10
7:59 a.m.
Hi, What are some interesting, idiomatic ways of writing something similar to the following, using a) Only standard utilities b) Non-standard utilities getValidatedInteger = do maybeInt <- maybeGet case maybeInt of Just int -> return int Nothing -> do putStrLn "That doesn't seem to be an integer. Try again." getValidatedInteger maybeGet :: (Read r) => IO (Maybe r) maybeGet = getLine >>= return . maybeReadS maybeReadS text = case reads text of [(int, rest)] | all (== ' ') rest -> Just int _ -> Nothing