From 5e172b43c4dc5d779e4f1af5c1376c9a8ebc60a4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 23 Jan 2012 16:57:45 -0400 Subject: [PATCH] a few things available elsewhere... --- Utility/PartialPrelude.hs | 8 ++++++-- Utility/Path.hs | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Utility/PartialPrelude.hs b/Utility/PartialPrelude.hs index 507fc6252b..dbdf4fa5c2 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 9f4fe29277..ed5e59cb5f 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