summaryrefslogtreecommitdiff
path: root/libraries/base/Data
diff options
context:
space:
mode:
authorOleg Grenrus <oleg.grenrus@iki.fi>2021-01-06 22:05:11 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-01-18 07:19:34 -0500
commit29c9eb3fefd145cd43850888d21b889bdf10c3df (patch)
tree2f84c6743a8db96db3d3a309484f2a0d1d512468 /libraries/base/Data
parentb1cafb82872784c224d297c748f9c78f47a39fd2 (diff)
downloadhaskell-29c9eb3fefd145cd43850888d21b889bdf10c3df.tar.gz
Add Eq1, Show1, Read1 Complex instances
Diffstat (limited to 'libraries/base/Data')
-rw-r--r--libraries/base/Data/Functor/Classes.hs20
1 files changed, 20 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