From 9901fc04a0dd9972e8910b5039a9e51e43d2c732 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 15 Dec 2011 18:23:07 -0400 Subject: move --- Utility/BadPrelude.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'Utility/BadPrelude.hs') 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 -- cgit v1.2.3