[Haskell-cafe] [Newbie question] -- Looping stdin until condition
is met
Neil Mitchell
ndmitchell at gmail.com
Mon Jun 2 19:07:32 EDT 2008
Hi
> The best thing to do is bypass read and use 'reads' to define your
> own safe read.
>
> maybeRead :: Read a => String -> Maybe a
> maybeRead s = case reads s of
> [(x, "")] -> Just x
> _ -> Nothing
Or just use the Safe package:
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/safe
http://hackage.haskell.org/packages/archive/safe/0.2/doc/html/Safe.html#v%3AreadMay
Thanks
Neil
More information about the Haskell-Cafe
mailing list