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


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to