
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

On 17 December 2010 13:59, Jacek Generowicz
What are some interesting, idiomatic ways of writing something similar to the following
λ> :m + Safe λ> let getValidatedInteger = getLine >>= maybe (do putStrLn "That doesn't seem to be an integer. Try again."; getValidatedInteger) return . readMay :: IO Integer Loading package safe-0.3 ... linking ... done. λ> getValidatedInteger a That doesn't seem to be an integer. Try again. 1 1 λ>
participants (2)
-
Christopher Done
-
Jacek Generowicz