summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-01-23 16:57:45 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-01-23 16:57:45 -0400
commit5e172b43c4dc5d779e4f1af5c1376c9a8ebc60a4 (patch)
tree312b16e8afcdfa792c87f8e35c7c82507aabda7a
parentbed495db644cc49f45ec2a4f49a572308fc586f7 (diff)
a few things available elsewhere...
-rw-r--r--Utility/PartialPrelude.hs8
-rw-r--r--Utility/Path.hs5
2 files changed, 10 insertions, 3 deletions
diff --git a/Utility/PartialPrelude.hs b/Utility/PartialPrelude.hs
index 507fc6252..dbdf4fa5c 100644
--- a/Utility/PartialPrelude.hs
+++ b/Utility/PartialPrelude.hs
@@ -7,6 +7,8 @@
module Utility.PartialPrelude where
+import qualified Data.Maybe
+
{- read should be avoided, as it throws an error
- Instead, use: readMaybe -}
read :: Read a => String -> a
@@ -36,6 +38,9 @@ last = Prelude.last
-
- Ignores leading/trailing whitespace, and throws away any trailing
- text after the part that can be read.
+ -
+ - readMaybe is available in Text.Read in new versions of GHC,
+ - but that one requires the entire string to be consumed.
-}
readMaybe :: Read a => String -> Maybe a
readMaybe s = case reads s of
@@ -44,8 +49,7 @@ readMaybe s = case reads s of
{- Like head but Nothing on empty list. -}
headMaybe :: [a] -> Maybe a
-headMaybe [] = Nothing
-headMaybe v = Just $ Prelude.head v
+headMaybe = Data.Maybe.listToMaybe
{- Like last but Nothing on empty list. -}
lastMaybe :: [a] -> Maybe a
diff --git a/Utility/Path.hs b/Utility/Path.hs
index 9f4fe2927..ed5e59cb5 100644
--- a/Utility/Path.hs
+++ b/Utility/Path.hs
@@ -47,7 +47,10 @@ dirContains a b = a == b || a' == b' || (a'++"/") `isPrefixOf` b'
a' = norm a
b' = norm b
-{- Converts a filename into a normalized, absolute path. -}
+{- Converts a filename into a normalized, absolute path.
+ -
+ - Unlike Directory.canonicalizePath, this does not require the path
+ - already exists. -}
absPath :: FilePath -> IO FilePath
absPath file = do
cwd <- getCurrentDirectory