prelude-extras 0.1.0.3 → 0.2
raw patch · 4 files changed
+231/−180 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Text.Read.Extras: instance Read a => Read1 ((,) a)
- Text.Read.Extras: instance Read a => Read1 (Either a)
- Text.Read.Extras: instance Read1 Maybe
- Text.Read.Extras: instance Read1 []
- Text.Read.Extras: instance Read2 (,)
- Text.Read.Extras: instance Read2 Either
- Text.Show.Extras: instance Show a => Show1 ((,) a)
- Text.Show.Extras: instance Show a => Show1 (Either a)
- Text.Show.Extras: instance Show1 Maybe
- Text.Show.Extras: instance Show1 []
- Text.Show.Extras: instance Show2 (,)
- Text.Show.Extras: instance Show2 Either
- Text.Show.Extras: showList__ :: (a -> ShowS) -> [a] -> ShowS
+ Prelude.Extras: Lift1 :: f a -> Lift1 f a
+ Prelude.Extras: Lift2 :: f a b -> Lift2 f a b
+ Prelude.Extras: class Read1 f where readsPrec1 = readPrec_to_S readPrec1 readList1 = readPrec_to_S (list readPrec1) 0 readPrec1 = readS_to_Prec readsPrec1 readListPrec1 = readS_to_Prec (\ _ -> readList1)
+ Prelude.Extras: class Read2 f where readsPrec2 = readPrec_to_S readPrec2 readList2 = readPrec_to_S (list readPrec2) 0 readPrec2 = readS_to_Prec readsPrec2 readListPrec2 = readS_to_Prec (\ _ -> readList2)
+ Prelude.Extras: class Show1 f where showsPrec1 _ x s = show1 x ++ s show1 x = shows1 x "" showList1 ls s = showList__ shows1 ls s
+ Prelude.Extras: class Show2 f where showsPrec2 _ x s = show2 x ++ s show2 x = shows2 x "" showList2 ls s = showList__ shows2 ls s
+ Prelude.Extras: instance (Eq1 f, Eq a) => Eq (Lift1 f a)
+ Prelude.Extras: instance (Eq2 f, Eq a) => Eq1 (Lift2 f a)
+ Prelude.Extras: instance (Eq2 f, Eq a, Eq b) => Eq (Lift2 f a b)
+ Prelude.Extras: instance (Ord1 f, Ord a) => Ord (Lift1 f a)
+ Prelude.Extras: instance (Ord2 f, Ord a) => Ord1 (Lift2 f a)
+ Prelude.Extras: instance (Ord2 f, Ord a, Ord b) => Ord (Lift2 f a b)
+ Prelude.Extras: instance (Read1 f, Read a) => Read (Lift1 f a)
+ Prelude.Extras: instance (Read2 f, Read a) => Read1 (Lift2 f a)
+ Prelude.Extras: instance (Read2 f, Read a, Read b) => Read (Lift2 f a b)
+ Prelude.Extras: instance (Show1 f, Show a) => Show (Lift1 f a)
+ Prelude.Extras: instance (Show2 f, Show a) => Show1 (Lift2 f a)
+ Prelude.Extras: instance (Show2 f, Show a, Show b) => Show (Lift2 f a b)
+ Prelude.Extras: instance Eq1 f => Eq1 (Lift1 f)
+ Prelude.Extras: instance Eq2 f => Eq2 (Lift2 f)
+ Prelude.Extras: instance Ord1 f => Ord1 (Lift1 f)
+ Prelude.Extras: instance Ord2 f => Ord2 (Lift2 f)
+ Prelude.Extras: instance Read a => Read1 ((,) a)
+ Prelude.Extras: instance Read a => Read1 (Either a)
+ Prelude.Extras: instance Read1 Maybe
+ Prelude.Extras: instance Read1 []
+ Prelude.Extras: instance Read1 f => Read1 (Lift1 f)
+ Prelude.Extras: instance Read2 (,)
+ Prelude.Extras: instance Read2 Either
+ Prelude.Extras: instance Read2 f => Read2 (Lift2 f)
+ Prelude.Extras: instance Show a => Show1 ((,) a)
+ Prelude.Extras: instance Show a => Show1 (Either a)
+ Prelude.Extras: instance Show1 Maybe
+ Prelude.Extras: instance Show1 []
+ Prelude.Extras: instance Show1 f => Show1 (Lift1 f)
+ Prelude.Extras: instance Show2 (,)
+ Prelude.Extras: instance Show2 Either
+ Prelude.Extras: instance Show2 f => Show2 (Lift2 f)
+ Prelude.Extras: lower1 :: Lift1 f a -> f a
+ Prelude.Extras: lower2 :: Lift2 f a b -> f a b
+ Prelude.Extras: newtype Lift1 f a
+ Prelude.Extras: newtype Lift2 f a b
+ Prelude.Extras: read1 :: (Read1 f, Read a) => String -> f a
+ Prelude.Extras: read2 :: (Read2 f, Read a, Read b) => String -> f a b
+ Prelude.Extras: readList1 :: (Read1 f, Read a) => ReadS [f a]
+ Prelude.Extras: readList1Default :: (Read1 f, Read a) => ReadS [f a]
+ Prelude.Extras: readList2 :: (Read2 f, Read a, Read b) => ReadS [f a b]
+ Prelude.Extras: readList2Default :: (Read2 f, Read a, Read b) => ReadS [f a b]
+ Prelude.Extras: readListPrec1 :: (Read1 f, Read a) => ReadPrec [f a]
+ Prelude.Extras: readListPrec1Default :: (Read1 f, Read a) => ReadPrec [f a]
+ Prelude.Extras: readListPrec2 :: (Read2 f, Read a, Read b) => ReadPrec [f a b]
+ Prelude.Extras: readListPrec2Default :: (Read2 f, Read a, Read b) => ReadPrec [f a b]
+ Prelude.Extras: readPrec1 :: (Read1 f, Read a) => ReadPrec (f a)
+ Prelude.Extras: readPrec2 :: (Read2 f, Read a, Read b) => ReadPrec (f a b)
+ Prelude.Extras: reads1 :: (Read1 f, Read a) => ReadS (f a)
+ Prelude.Extras: reads2 :: (Read2 f, Read a, Read b) => ReadS (f a b)
+ Prelude.Extras: readsPrec1 :: (Read1 f, Read a) => Int -> ReadS (f a)
+ Prelude.Extras: readsPrec2 :: (Read2 f, Read a, Read b) => Int -> ReadS (f a b)
+ Prelude.Extras: show1 :: (Show1 f, Show a) => f a -> String
+ Prelude.Extras: show2 :: (Show2 f, Show a, Show b) => f a b -> String
+ Prelude.Extras: showList1 :: (Show1 f, Show a) => [f a] -> ShowS
+ Prelude.Extras: showList2 :: (Show2 f, Show a, Show b) => [f a b] -> ShowS
+ Prelude.Extras: shows1 :: (Show1 f, Show a) => f a -> ShowS
+ Prelude.Extras: shows2 :: (Show2 f, Show a, Show b) => f a b -> ShowS
+ Prelude.Extras: showsPrec1 :: (Show1 f, Show a) => Int -> f a -> ShowS
+ Prelude.Extras: showsPrec2 :: (Show2 f, Show a, Show b) => Int -> f a b -> ShowS
Files
- Prelude/Extras.hs +223/−7
- Text/Read/Extras.hs +2/−131
- Text/Show/Extras.hs +5/−40
- prelude-extras.cabal +1/−2
Prelude/Extras.hs view
@@ -1,12 +1,32 @@-module Prelude.Extras - ( Eq1(..), Ord1(..)- , Eq2(..), Ord2(..)- , module Text.Show.Extras- , module Text.Read.Extras+{-# LANGUAGE CPP #-}+module Prelude.Extras+ (+ -- * Lifted Prelude classes for kind * -> *+ Eq1(..)+ , Ord1(..)+ , Show1(..), shows1+ , Read1(..), read1, reads1+#ifdef __GLASGOW_HASKELL__+ , readList1Default -- :: (Read1 f, Read a) => ReadS [f a]+ , readListPrec1Default -- :: (Read1 f, Read a) => ReadPrec [f a]+#endif+ , Lift1(..)+ -- * Lifted Prelude classes for kind * -> * -> *+ , Eq2(..)+ , Ord2(..)+ , Show2(..), shows2+ , Read2(..), read2, reads2+#ifdef __GLASGOW_HASKELL__+ , readList2Default -- :: (Read1 f, Read a) => ReadS [f a]+ , readListPrec2Default -- :: (Read1 f, Read a) => ReadPrec [f a]+#endif+ , Lift2(..) ) where -import Text.Show.Extras-import Text.Read.Extras+import Control.Monad (liftM)+import Text.Read+import qualified Text.ParserCombinators.ReadP as P+import qualified Text.Read.Lex as L infixr 4 ==#, /=#, <#, <=#, >=#, ># infixr 4 ==##, /=##, <##, <=##, >=##, >##@@ -87,3 +107,199 @@ | otherwise = y instance Ord2 Either where compare2 = compare++class Show1 f where+ showsPrec1 :: Show a => Int -> f a -> ShowS+ show1 :: Show a => f a -> String+ showList1 :: Show a => [f a] -> ShowS+ showsPrec1 _ x s = show1 x ++ s+ show1 x = shows1 x ""+ showList1 ls s = showList__ shows1 ls s++shows1 :: (Show1 f, Show a) => f a -> ShowS+shows1 = showsPrec1 0++instance Show1 Maybe where showsPrec1 = showsPrec+instance Show1 [] where showsPrec1 = showsPrec+instance Show a => Show1 (Either a) where showsPrec1 = showsPrec+instance Show a => Show1 ((,) a) where showsPrec1 = showsPrec++-- instance Show1 Complex++class Show2 f where + showsPrec2 :: (Show a, Show b) => Int -> f a b -> ShowS+ show2 :: (Show a, Show b) => f a b -> String+ showList2 :: (Show a, Show b) => [f a b] -> ShowS++ showsPrec2 _ x s = show2 x ++ s+ show2 x = shows2 x ""+ showList2 ls s = showList__ shows2 ls s++shows2 :: (Show2 f, Show a, Show b) => f a b -> ShowS+shows2 = showsPrec2 0++instance Show2 (,) where showsPrec2 = showsPrec+instance Show2 Either where showsPrec2 = showsPrec++showList__ :: (a -> ShowS) -> [a] -> ShowS+showList__ _ [] s = "[]" ++ s+showList__ showx (x:xs) s = '[' : showx x (showl xs)+ where+ showl [] = ']' : s+ showl (y:ys) = ',' : showx y (showl ys)+++class Read1 f where+ readsPrec1 :: Read a => Int -> ReadS (f a)+ readList1 :: Read a => ReadS [f a]++ readsPrec1 = readPrec_to_S readPrec1+ readList1 = readPrec_to_S (list readPrec1) 0 ++#ifdef __GLASGOW_HASKELL__+ readPrec1 :: Read a => ReadPrec (f a)+ readListPrec1 :: Read a => ReadPrec [f a]++ readPrec1 = readS_to_Prec readsPrec1+ readListPrec1 = readS_to_Prec (\_ -> readList1)+#endif++read1 :: (Read1 f, Read a) => String -> f a+read1 s = either error id (readEither1 s)++reads1 :: (Read1 f, Read a) => ReadS (f a)+reads1 = readsPrec1 minPrec++readEither1 :: (Read1 f, Read a) => String -> Either String (f a)+readEither1 s =+ case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of+ [x] -> Right x+ [] -> Left "Prelude.read: no parse"+ _ -> Left "Prelude.read: ambiguous parse"+ where+ read' =+ do x <- readPrec1+ lift P.skipSpaces+ return x++#ifdef __GLASGOW_HASKELL__+readList1Default :: (Read1 f, Read a) => ReadS [f a]+readList1Default = readPrec_to_S readListPrec1 0++readListPrec1Default :: (Read1 f, Read a) => ReadPrec [f a]+readListPrec1Default = list readPrec1+#endif++instance Read1 [] where+ readsPrec1 = readsPrec+ readList1 = readList++instance Read1 Maybe where+ readsPrec1 = readsPrec+ readList1 = readList++instance Read a => Read1 (Either a) where+ readsPrec1 = readsPrec+ readList1 = readList++instance Read a => Read1 ((,) a) where+ readsPrec1 = readsPrec+ readList1 = readList++class Read2 f where+ readsPrec2 :: (Read a, Read b) => Int -> ReadS (f a b)+ readList2 :: (Read a, Read b) => ReadS [f a b]+ readsPrec2 = readPrec_to_S readPrec2+ readList2 = readPrec_to_S (list readPrec2) 0 ++#ifdef __GLASGOW_HASKELL__+ readPrec2 :: (Read a, Read b) => ReadPrec (f a b)+ readListPrec2 :: (Read a, Read b) => ReadPrec [f a b]+ readPrec2 = readS_to_Prec readsPrec2+ readListPrec2 = readS_to_Prec (\_ -> readList2)+#endif++instance Read2 (,) where+ readsPrec2 = readsPrec+ readList2 = readList++instance Read2 Either where+ readsPrec2 = readsPrec+ readList2 = readList++read2 :: (Read2 f, Read a, Read b) => String -> f a b+read2 s = either error id (readEither2 s)++reads2 :: (Read2 f, Read a, Read b) => ReadS (f a b)+reads2 = readsPrec2 minPrec++readEither2 :: (Read2 f, Read a, Read b) => String -> Either String (f a b)+readEither2 s =+ case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of+ [x] -> Right x+ [] -> Left "Prelude.read: no parse"+ _ -> Left "Prelude.read: ambiguous parse"+ where+ read' =+ do x <- readPrec2+ lift P.skipSpaces+ return x++#ifdef __GLASGOW_HASKELL__+readList2Default :: (Read2 f, Read a, Read b) => ReadS [f a b]+readList2Default = readPrec_to_S readListPrec2 0++readListPrec2Default :: (Read2 f, Read a, Read b) => ReadPrec [f a b]+readListPrec2Default = list readPrec2+#endif++-- annoying to hav to copy these from Text.Read+list :: ReadPrec a -> ReadPrec [a]+-- ^ @(list p)@ parses a list of things parsed by @p@,+-- using the usual square-bracket syntax.+list readx =+ parens+ ( do L.Punc "[" <- lexP+ (listRest False +++ listNext)+ )+ where+ listRest started =+ do L.Punc c <- lexP+ case c of+ "]" -> return []+ "," | started -> listNext+ _ -> pfail++ listNext =+ do x <- reset readx+ xs <- listRest True+ return (x:xs)++newtype Lift1 f a = Lift1 { lower1 :: f a }++instance Eq1 f => Eq1 (Lift1 f) where Lift1 a ==# Lift1 b = a ==# b+instance Ord1 f => Ord1 (Lift1 f) where Lift1 a `compare1` Lift1 b = compare1 a b+instance Show1 f => Show1 (Lift1 f) where showsPrec1 d (Lift1 a) = showsPrec1 d a+instance Read1 f => Read1 (Lift1 f) where readPrec1 = liftM Lift1 readPrec1++instance (Eq1 f, Eq a) => Eq (Lift1 f a) where Lift1 a == Lift1 b = a ==# b+instance (Ord1 f, Ord a) => Ord (Lift1 f a) where Lift1 a `compare` Lift1 b = compare1 a b+instance (Show1 f, Show a) => Show (Lift1 f a) where showsPrec d (Lift1 a) = showsPrec1 d a+instance (Read1 f, Read a) => Read (Lift1 f a) where readPrec = liftM Lift1 readPrec1++newtype Lift2 f a b = Lift2 { lower2 :: f a b }++instance Eq2 f => Eq2 (Lift2 f) where Lift2 a ==## Lift2 b = a ==## b+instance Ord2 f => Ord2 (Lift2 f) where Lift2 a `compare2` Lift2 b = compare2 a b+instance Show2 f => Show2 (Lift2 f) where showsPrec2 d (Lift2 a) = showsPrec2 d a+instance Read2 f => Read2 (Lift2 f) where readPrec2 = liftM Lift2 readPrec2++instance (Eq2 f, Eq a) => Eq1 (Lift2 f a) where Lift2 a ==# Lift2 b = a ==## b+instance (Ord2 f, Ord a) => Ord1 (Lift2 f a) where Lift2 a `compare1` Lift2 b = compare2 a b+instance (Show2 f, Show a) => Show1 (Lift2 f a) where showsPrec1 d (Lift2 a) = showsPrec2 d a+instance (Read2 f, Read a) => Read1 (Lift2 f a) where readPrec1 = liftM Lift2 readPrec2++instance (Eq2 f, Eq a, Eq b) => Eq (Lift2 f a b) where Lift2 a == Lift2 b = a ==## b+instance (Ord2 f, Ord a, Ord b) => Ord (Lift2 f a b) where Lift2 a `compare` Lift2 b = compare2 a b+instance (Show2 f, Show a, Show b) => Show (Lift2 f a b) where showsPrec d (Lift2 a) = showsPrec2 d a+instance (Read2 f, Read a, Read b) => Read (Lift2 f a b) where readPrec = liftM Lift2 readPrec2
Text/Read/Extras.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-}--module Text.Read.Extras +module Text.Read.Extras ( Read1(..), read1, reads1 , Read2(..), read2, reads2 #ifdef __GLASGOW_HASKELL__@@ -11,132 +10,4 @@ #endif ) where -import Text.Read-import qualified Text.ParserCombinators.ReadP as P-import qualified Text.Read.Lex as L--class Read1 f where- readsPrec1 :: Read a => Int -> ReadS (f a)- readList1 :: Read a => ReadS [f a]-- readsPrec1 = readPrec_to_S readPrec1- readList1 = readPrec_to_S (list readPrec1) 0 --#ifdef __GLASGOW_HASKELL__- readPrec1 :: Read a => ReadPrec (f a)- readListPrec1 :: Read a => ReadPrec [f a]-- readPrec1 = readS_to_Prec readsPrec1- readListPrec1 = readS_to_Prec (\_ -> readList1)-#endif--read1 :: (Read1 f, Read a) => String -> f a-read1 s = either error id (readEither1 s)--reads1 :: (Read1 f, Read a) => ReadS (f a)-reads1 = readsPrec1 minPrec--readEither1 :: (Read1 f, Read a) => String -> Either String (f a)-readEither1 s =- case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of- [x] -> Right x- [] -> Left "Prelude.read: no parse"- _ -> Left "Prelude.read: ambiguous parse"- where- read' =- do x <- readPrec1- lift P.skipSpaces- return x--#ifdef __GLASGOW_HASKELL__-readList1Default :: (Read1 f, Read a) => ReadS [f a]-readList1Default = readPrec_to_S readListPrec1 0--readListPrec1Default :: (Read1 f, Read a) => ReadPrec [f a]-readListPrec1Default = list readPrec1-#endif--instance Read1 [] where- readsPrec1 = readsPrec- readList1 = readList--instance Read1 Maybe where- readsPrec1 = readsPrec- readList1 = readList--instance Read a => Read1 (Either a) where- readsPrec1 = readsPrec- readList1 = readList--instance Read a => Read1 ((,) a) where- readsPrec1 = readsPrec- readList1 = readList--class Read2 f where- readsPrec2 :: (Read a, Read b) => Int -> ReadS (f a b)- readList2 :: (Read a, Read b) => ReadS [f a b]- readsPrec2 = readPrec_to_S readPrec2- readList2 = readPrec_to_S (list readPrec2) 0 --#ifdef __GLASGOW_HASKELL__- readPrec2 :: (Read a, Read b) => ReadPrec (f a b)- readListPrec2 :: (Read a, Read b) => ReadPrec [f a b]- readPrec2 = readS_to_Prec readsPrec2- readListPrec2 = readS_to_Prec (\_ -> readList2)-#endif--instance Read2 (,) where- readsPrec2 = readsPrec- readList2 = readList--instance Read2 Either where- readsPrec2 = readsPrec- readList2 = readList--read2 :: (Read2 f, Read a, Read b) => String -> f a b-read2 s = either error id (readEither2 s)--reads2 :: (Read2 f, Read a, Read b) => ReadS (f a b)-reads2 = readsPrec2 minPrec--readEither2 :: (Read2 f, Read a, Read b) => String -> Either String (f a b)-readEither2 s =- case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of- [x] -> Right x- [] -> Left "Prelude.read: no parse"- _ -> Left "Prelude.read: ambiguous parse"- where- read' =- do x <- readPrec2- lift P.skipSpaces- return x--#ifdef __GLASGOW_HASKELL__-readList2Default :: (Read2 f, Read a, Read b) => ReadS [f a b]-readList2Default = readPrec_to_S readListPrec2 0--readListPrec2Default :: (Read2 f, Read a, Read b) => ReadPrec [f a b]-readListPrec2Default = list readPrec2-#endif---- annoying to hav to copy these from Text.Read-list :: ReadPrec a -> ReadPrec [a]--- ^ @(list p)@ parses a list of things parsed by @p@,--- using the usual square-bracket syntax.-list readx =- parens- ( do L.Punc "[" <- lexP- (listRest False +++ listNext)- )- where- listRest started =- do L.Punc c <- lexP- case c of- "]" -> return []- "," | started -> listNext- _ -> pfail- - listNext =- do x <- reset readx- xs <- listRest True- return (x:xs)+import Prelude.Extras
Text/Show/Extras.hs view
@@ -1,41 +1,6 @@-module Text.Show.Extras where--class Show1 f where - showsPrec1 :: Show a => Int -> f a -> ShowS- show1 :: Show a => f a -> String- showList1 :: Show a => [f a] -> ShowS- showsPrec1 _ x s = show1 x ++ s- show1 x = shows1 x ""- showList1 ls s = showList__ shows1 ls s--shows1 :: (Show1 f, Show a) => f a -> ShowS-shows1 = showsPrec1 0--instance Show1 Maybe where showsPrec1 = showsPrec-instance Show1 [] where showsPrec1 = showsPrec-instance Show a => Show1 (Either a) where showsPrec1 = showsPrec-instance Show a => Show1 ((,) a) where showsPrec1 = showsPrec---- instance Show1 Complex--class Show2 f where - showsPrec2 :: (Show a, Show b) => Int -> f a b -> ShowS- show2 :: (Show a, Show b) => f a b -> String- showList2 :: (Show a, Show b) => [f a b] -> ShowS-- showsPrec2 _ x s = show2 x ++ s- show2 x = shows2 x ""- showList2 ls s = showList__ shows2 ls s--shows2 :: (Show2 f, Show a, Show b) => f a b -> ShowS-shows2 = showsPrec2 0--instance Show2 (,) where showsPrec2 = showsPrec-instance Show2 Either where showsPrec2 = showsPrec+module Text.Show.Extras+ ( Show1(..), shows1+ , Show2(..), shows2+ ) where -showList__ :: (a -> ShowS) -> [a] -> ShowS-showList__ _ [] s = "[]" ++ s-showList__ showx (x:xs) s = '[' : showx x (showl xs)- where- showl [] = ']' : s- showl (y:ys) = ',' : showx y (showl ys)+import Prelude.Extras
prelude-extras.cabal view
@@ -1,6 +1,6 @@ name: prelude-extras category: Polymorphism, Combinators-version: 0.1.0.3+version: 0.2 license: BSD3 cabal-version: >= 1.2 license-file: LICENSE@@ -30,4 +30,3 @@ Prelude.Extras, Text.Show.Extras, Text.Read.Extras-