diff options
author | Oleg Grenrus <oleg.grenrus@iki.fi> | 2021-01-06 22:05:11 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-01-18 07:19:34 -0500 |
commit | 29c9eb3fefd145cd43850888d21b889bdf10c3df (patch) | |
tree | 2f84c6743a8db96db3d3a309484f2a0d1d512468 /libraries | |
parent | b1cafb82872784c224d297c748f9c78f47a39fd2 (diff) | |
download | haskell-29c9eb3fefd145cd43850888d21b889bdf10c3df.tar.gz |
Add Eq1, Show1, Read1 Complex instances
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Data/Functor/Classes.hs | 20 | ||||
-rw-r--r-- | libraries/base/changelog.md | 3 |
2 files changed, 23 insertions, 0 deletions
diff --git a/libraries/base/Data/Functor/Classes.hs b/libraries/base/Data/Functor/Classes.hs index e719c8ffe8..80b662372c 100644 --- a/libraries/base/Data/Functor/Classes.hs +++ b/libraries/base/Data/Functor/Classes.hs @@ -70,6 +70,7 @@ import Data.Functor.Identity (Identity(Identity)) import Data.Proxy (Proxy(Proxy)) import Data.List.NonEmpty (NonEmpty(..)) import Data.Ord (Down(Down)) +import Data.Complex (Complex((:+))) import GHC.Read (expectP, list, paren) @@ -661,6 +662,25 @@ instance Read1 Down where instance Show1 Down where liftShowsPrec sp _ d (Down x) = showsUnaryWith sp "Down" d x +-- | @since 4.16.0.0 +instance Eq1 Complex where + liftEq eq (x :+ y) (u :+ v) = eq x u && eq y v + +-- | @since 4.16.0.0 +instance Read1 Complex where + liftReadPrec rp _ = parens $ prec 9 $ do + x <- step rp + expectP (Symbol ":+") + y <- step rp + return (x :+ y) + + liftReadListPrec = liftReadListPrecDefault + liftReadList = liftReadListDefault + +-- | @since 4.16.0.0 +instance Show1 Complex where + liftShowsPrec sp _ d (x :+ y) = showParen (d >= 10) $ + sp 10 x . showString " :+ " . sp 10 y -- Building blocks diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index 9c25b92b4c..71649ad175 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -11,6 +11,9 @@ * Add `Semigroup` and `Monoid` instances for `Data.Functor.Product` and `Data.Functor.Compose`. + * Add `Eq1`, `Read1` and `Show1` instance for `Complex`; + add `Eq1`, `Ord1`, `Show1` and `Read1` instances for 3 and 4-tuples. + ## 4.15.0.0 *TBA* * `openFile` now calls the `open` system call with an `interruptible` FFI |