transformers-compat 0.7 → 0.7.1
raw patch · 5 files changed
+248/−3 lines, 5 files
Files
- 0.3/Data/Functor/Classes.hs +106/−0
- CHANGELOG.markdown +7/−0
- src/Control/Monad/Trans/Instances.hs +130/−0
- tests/transformers-compat-tests.cabal +2/−1
- transformers-compat.cabal +3/−2
0.3/Data/Functor/Classes.hs view
@@ -92,6 +92,7 @@ import Data.Functor.Compose import Data.Functor.Constant import Data.Functor.Product+import Data.Complex (Complex (..)) #if MIN_VERSION_transformers(0,3,0) import Control.Applicative.Lift@@ -99,6 +100,7 @@ import Data.Functor.Reverse #endif + #ifndef HASKELL98 # if __GLASGOW_HASKELL__ >= 708 import Data.Typeable@@ -829,6 +831,110 @@ deriving instance Typeable Show2 # endif #endif++#if MIN_VERSION_base(4,4,0)+instance Eq1 Complex where+ liftEq eq (x :+ y) (u :+ v) = eq x u && eq y v++instance Read1 Complex where+ liftReadsPrec rdP _ p s = readParen (p > complexPrec) (\s' -> do+ (x, s'') <- rdP (complexPrec+1) s'+ (":+", s''') <- lex s''+ (y, s'''') <- rdP (complexPrec+1) s'''+ return (x :+ y, s'''')) s+ where+ complexPrec = 6++instance Show1 Complex where+ liftShowsPrec sp _ d (x :+ y) = showParen (d > complexPrec) $+ sp (complexPrec+1) x . showString " :+ " . sp (complexPrec+1) y+ where+ complexPrec = 6+#endif++instance Eq a => Eq2 ((,,) a) where+ liftEq2 e1 e2 (u1, x1, y1) (v1, x2, y2) =+ u1 == v1 &&+ e1 x1 x2 && e2 y1 y2++instance Ord a => Ord2 ((,,) a) where+ liftCompare2 comp1 comp2 (u1, x1, y1) (v1, x2, y2) =+ compare u1 v1 `mappend`+ comp1 x1 x2 `mappend` comp2 y1 y2++instance Read a => Read2 ((,,) a) where+ liftReadsPrec2 rp1 _ rp2 _ _ = readParen False $ \ r ->+ [((e1,e2,e3), y) | ("(",s) <- lex r,+ (e1,t) <- readsPrec 0 s,+ (",",u) <- lex t,+ (e2,v) <- rp1 0 u,+ (",",w) <- lex v,+ (e3,x) <- rp2 0 w,+ (")",y) <- lex x]++instance Show a => Show2 ((,,) a) where+ liftShowsPrec2 sp1 _ sp2 _ _ (x1,y1,y2)+ = showChar '(' . showsPrec 0 x1+ . showChar ',' . sp1 0 y1+ . showChar ',' . sp2 0 y2+ . showChar ')'++instance (Eq a, Eq b) => Eq1 ((,,) a b) where+ liftEq = liftEq2 (==)++instance (Ord a, Ord b) => Ord1 ((,,) a b) where+ liftCompare = liftCompare2 compare++instance (Read a, Read b) => Read1 ((,,) a b) where+ liftReadsPrec = liftReadsPrec2 readsPrec readList++instance (Show a, Show b) => Show1 ((,,) a b) where+ liftShowsPrec = liftShowsPrec2 showsPrec showList++instance (Eq a, Eq b) => Eq2 ((,,,) a b) where+ liftEq2 e1 e2 (u1, u2, x1, y1) (v1, v2, x2, y2) =+ u1 == v1 &&+ u2 == v2 &&+ e1 x1 x2 && e2 y1 y2++instance (Ord a, Ord b) => Ord2 ((,,,) a b) where+ liftCompare2 comp1 comp2 (u1, u2, x1, y1) (v1, v2, x2, y2) =+ compare u1 v1 `mappend`+ compare u2 v2 `mappend`+ comp1 x1 x2 `mappend` comp2 y1 y2++instance (Read a, Read b) => Read2 ((,,,) a b) where+ liftReadsPrec2 rp1 _ rp2 _ _ = readParen False $ \ r ->+ [((e1,e2,e3,e4), s9) | ("(",s1) <- lex r,+ (e1,s2) <- readsPrec 0 s1,+ (",",s3) <- lex s2,+ (e2,s4) <- readsPrec 0 s3,+ (",",s5) <- lex s4,+ (e3,s6) <- rp1 0 s5,+ (",",s7) <- lex s6,+ (e4,s8) <- rp2 0 s7,+ (")",s9) <- lex s8]++instance (Show a, Show b) => Show2 ((,,,) a b) where+ liftShowsPrec2 sp1 _ sp2 _ _ (x1,x2,y1,y2)+ = showChar '(' . showsPrec 0 x1+ . showChar ',' . showsPrec 0 x2+ . showChar ',' . sp1 0 y1+ . showChar ',' . sp2 0 y2+ . showChar ')'++instance (Eq a, Eq b, Eq c) => Eq1 ((,,,) a b c) where+ liftEq = liftEq2 (==)++instance (Ord a, Ord b, Ord c) => Ord1 ((,,,) a b c) where+ liftCompare = liftCompare2 compare++instance (Read a, Read b, Read c) => Read1 ((,,,) a b c) where+ liftReadsPrec = liftReadsPrec2 readsPrec readList++instance (Show a, Show b, Show c) => Show1 ((,,,) a b c) where+ liftShowsPrec = liftShowsPrec2 showsPrec showList+ {- $example These functions can be used to assemble 'Read' and 'Show' instances for
CHANGELOG.markdown view
@@ -1,3 +1,10 @@+0.7.1 [2021.10.30]+------------------+* Backport new instances from GHC 9.2/`base-4.16`+ * `Eq1`, `Read1`, and `Show1` instances for `Complex`+ * `Eq{1,2}`, `Ord{1,2}`, `Show{1,2}`, and `Read{1,2}` instances for `(,,)`+ and `(,,,)`+ 0.7 [2021.07.25] ---------------- * Backport changes from `transformers-0.6.*`:
src/Control/Monad/Trans/Instances.hs view
@@ -88,6 +88,10 @@ import Data.Traversable (Traversable(..)) import Foreign (Storable(..), castPtr) +#if MIN_VERSION_base(4,4,0) && !(MIN_VERSION_base(4,9,0))+import Data.Complex (Complex (..))+#endif+ #if !(MIN_VERSION_transformers(0,6,0)) import Control.Monad.Trans.Error (Error(..), ErrorT(..)) import Control.Monad.Trans.List (ListT(..), mapListT)@@ -1246,5 +1250,131 @@ # endif # endif+# endif+#endif++#if !(MIN_VERSION_base(4,9,0))+# if defined(TRANSFORMERS_FOUR)++# if MIN_VERSION_base(4,4,0)+instance Eq1 Complex where eq1 = (==)+instance Read1 Complex where readsPrec1 = readsPrec+instance Show1 Complex where showsPrec1 = showsPrec+# endif++instance (Eq a, Eq b) => Eq1 ((,,) a b) where eq1 = (==)+instance (Ord a, Ord b) => Ord1 ((,,) a b) where compare1 = compare+instance (Read a, Read b) => Read1 ((,,) a b) where readsPrec1 = readsPrec+instance (Show a, Show b) => Show1 ((,,) a b) where showsPrec1 = showsPrec++instance (Eq a, Eq b, Eq c) => Eq1 ((,,,) a b c) where eq1 = (==)+instance (Ord a, Ord b, Ord c) => Ord1 ((,,,) a b c) where compare1 = compare+instance (Read a, Read b, Read c) => Read1 ((,,,) a b c) where readsPrec1 = readsPrec+instance (Show a, Show b, Show c) => Show1 ((,,,) a b c) where showsPrec1 = showsPrec+# elif MIN_VERSION_transformers(0,5,0)++# if MIN_VERSION_base(4,4,0)+instance Eq1 Complex where+ liftEq eq (x :+ y) (u :+ v) = eq x u && eq y v++instance Read1 Complex where+ liftReadsPrec rdP _ p s = readParen (p > complexPrec) (\s' -> do+ (x, s'') <- rdP (complexPrec+1) s'+ (":+", s''') <- lex s''+ (y, s'''') <- rdP (complexPrec+1) s'''+ return (x :+ y, s'''')) s+ where+ complexPrec = 6++instance Show1 Complex where+ liftShowsPrec sp _ d (x :+ y) = showParen (d > complexPrec) $+ sp (complexPrec+1) x . showString " :+ " . sp (complexPrec+1) y+ where+ complexPrec = 6+# endif++instance Eq a => Eq2 ((,,) a) where+ liftEq2 e1 e2 (u1, x1, y1) (v1, x2, y2) =+ u1 == v1 &&+ e1 x1 x2 && e2 y1 y2++instance Ord a => Ord2 ((,,) a) where+ liftCompare2 comp1 comp2 (u1, x1, y1) (v1, x2, y2) =+ compare u1 v1 `mappend`+ comp1 x1 x2 `mappend` comp2 y1 y2++instance Read a => Read2 ((,,) a) where+ liftReadsPrec2 rp1 _ rp2 _ _ = readParen False $ \ r ->+ [((e1,e2,e3), y) | ("(",s) <- lex r,+ (e1,t) <- readsPrec 0 s,+ (",",u) <- lex t,+ (e2,v) <- rp1 0 u,+ (",",w) <- lex v,+ (e3,x) <- rp2 0 w,+ (")",y) <- lex x]++instance Show a => Show2 ((,,) a) where+ liftShowsPrec2 sp1 _ sp2 _ _ (x1,y1,y2)+ = showChar '(' . showsPrec 0 x1+ . showChar ',' . sp1 0 y1+ . showChar ',' . sp2 0 y2+ . showChar ')'++instance (Eq a, Eq b) => Eq1 ((,,) a b) where+ liftEq = liftEq2 (==)++instance (Ord a, Ord b) => Ord1 ((,,) a b) where+ liftCompare = liftCompare2 compare++instance (Read a, Read b) => Read1 ((,,) a b) where+ liftReadsPrec = liftReadsPrec2 readsPrec readList++instance (Show a, Show b) => Show1 ((,,) a b) where+ liftShowsPrec = liftShowsPrec2 showsPrec showList++instance (Eq a, Eq b) => Eq2 ((,,,) a b) where+ liftEq2 e1 e2 (u1, u2, x1, y1) (v1, v2, x2, y2) =+ u1 == v1 &&+ u2 == v2 &&+ e1 x1 x2 && e2 y1 y2++instance (Ord a, Ord b) => Ord2 ((,,,) a b) where+ liftCompare2 comp1 comp2 (u1, u2, x1, y1) (v1, v2, x2, y2) =+ compare u1 v1 `mappend`+ compare u2 v2 `mappend`+ comp1 x1 x2 `mappend` comp2 y1 y2++instance (Read a, Read b) => Read2 ((,,,) a b) where+ liftReadsPrec2 rp1 _ rp2 _ _ = readParen False $ \ r ->+ [((e1,e2,e3,e4), s9) | ("(",s1) <- lex r,+ (e1,s2) <- readsPrec 0 s1,+ (",",s3) <- lex s2,+ (e2,s4) <- readsPrec 0 s3,+ (",",s5) <- lex s4,+ (e3,s6) <- rp1 0 s5,+ (",",s7) <- lex s6,+ (e4,s8) <- rp2 0 s7,+ (")",s9) <- lex s8]++instance (Show a, Show b) => Show2 ((,,,) a b) where+ liftShowsPrec2 sp1 _ sp2 _ _ (x1,x2,y1,y2)+ = showChar '(' . showsPrec 0 x1+ . showChar ',' . showsPrec 0 x2+ . showChar ',' . sp1 0 y1+ . showChar ',' . sp2 0 y2+ . showChar ')'++instance (Eq a, Eq b, Eq c) => Eq1 ((,,,) a b c) where+ liftEq = liftEq2 (==)++instance (Ord a, Ord b, Ord c) => Ord1 ((,,,) a b c) where+ liftCompare = liftCompare2 compare++instance (Read a, Read b, Read c) => Read1 ((,,,) a b c) where+ liftReadsPrec = liftReadsPrec2 readsPrec readList++instance (Show a, Show b, Show c) => Show1 ((,,,) a b c) where+ liftShowsPrec = liftShowsPrec2 showsPrec showList+ # endif #endif
tests/transformers-compat-tests.cabal view
@@ -24,8 +24,9 @@ , GHC == 8.4.4 , GHC == 8.6.5 , GHC == 8.8.4- , GHC == 8.10.4+ , GHC == 8.10.7 , GHC == 9.0.1+ , GHC == 9.2.1 source-repository head type: git
transformers-compat.cabal view
@@ -1,6 +1,6 @@ name: transformers-compat category: Compatibility-version: 0.7+version: 0.7.1 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE@@ -34,8 +34,9 @@ , GHC == 8.4.4 , GHC == 8.6.5 , GHC == 8.8.4- , GHC == 8.10.4+ , GHC == 8.10.7 , GHC == 9.0.1+ , GHC == 9.2.1 extra-source-files: .ghci .gitignore