summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-15 18:23:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-15 18:23:07 -0400
commit9901fc04a0dd9972e8910b5039a9e51e43d2c732 (patch)
tree0ced643f825fcd69731280dd4d04c8d0a48fdffd /Utility
parent95d2391f58ae240e7100f0d5488dd7246f71f3bb (diff)
move
Diffstat (limited to 'Utility')
-rw-r--r--Utility/BadPrelude.hs13
-rw-r--r--Utility/Misc.hs6
2 files changed, 12 insertions, 7 deletions
diff --git a/Utility/BadPrelude.hs b/Utility/BadPrelude.hs
index 47d38ae7b..825adfa02 100644
--- a/Utility/BadPrelude.hs
+++ b/Utility/BadPrelude.hs
@@ -7,7 +7,8 @@
module Utility.BadPrelude where
-{- read should be avoided, as it throws an error -}
+{- read should be avoided, as it throws an error
+ - Instead, use: readMaybe -}
read :: Read a => String -> a
read = Prelude.read
@@ -31,6 +32,16 @@ init = Prelude.init
last :: [a] -> a
last = Prelude.last
+{- Attempts to read a value from a String.
+ -
+ - Ignores leading/trailing whitespace, and throws away any trailing
+ - text after the part that can be read.
+ -}
+readMaybe :: (Read a) => String -> Maybe a
+readMaybe s = case reads s of
+ ((x,_):_) -> Just x
+ _ -> Nothing
+
{- Like head but Nothing on empty list. -}
headMaybe :: [a] -> Maybe a
headMaybe [] = Nothing
diff --git a/Utility/Misc.hs b/Utility/Misc.hs
index e95ac4319..1d3c0e676 100644
--- a/Utility/Misc.hs
+++ b/Utility/Misc.hs
@@ -21,12 +21,6 @@ hGetContentsStrict = hGetContents >=> \s -> length s `seq` return s
readFileStrict :: FilePath -> IO String
readFileStrict = readFile >=> \s -> length s `seq` return s
-{- Attempts to read a value from a String. -}
-readMaybe :: (Read a) => String -> Maybe a
-readMaybe s = case reads s of
- ((x,_):_) -> Just x
- _ -> Nothing
-
{- Like break, but the character matching the condition is not included
- in the second result list.
-