[commit: ghc] master: Added Eq1, Ord1, Read1 and Show1 instances for NonEmpty (b92f8e3)
git at git.haskell.org
git at git.haskell.org
Wed Nov 30 01:38:40 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/b92f8e38b1d58bef55b4fec67c1f0807e960512d/ghc
>---------------------------------------------------------------
commit b92f8e38b1d58bef55b4fec67c1f0807e960512d
Author: Shane <shane at duairc.com>
Date: Tue Nov 29 17:53:44 2016 -0500
Added Eq1, Ord1, Read1 and Show1 instances for NonEmpty
Reviewers: austin, hvr, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2755
>---------------------------------------------------------------
b92f8e38b1d58bef55b4fec67c1f0807e960512d
libraries/base/Data/List/NonEmpty.hs | 23 +++++++++++++++++++++++
libraries/base/changelog.md | 2 ++
2 files changed, 25 insertions(+)
diff --git a/libraries/base/Data/List/NonEmpty.hs b/libraries/base/Data/List/NonEmpty.hs
index 1cba3e5..b4da532 100644
--- a/libraries/base/Data/List/NonEmpty.hs
+++ b/libraries/base/Data/List/NonEmpty.hs
@@ -109,7 +109,9 @@ import Data.Data (Data)
import Data.Foldable hiding (length, toList)
import qualified Data.Foldable as Foldable
import Data.Function (on)
+import Data.Functor.Classes (Eq1(..), Ord1(..), Read1(..), Show1(..))
import qualified Data.List as List
+import Data.Monoid ((<>))
import Data.Ord (comparing)
import qualified GHC.Exts as Exts (IsList(..))
import GHC.Generics (Generic, Generic1)
@@ -122,6 +124,27 @@ infixr 5 :|, <|
data NonEmpty a = a :| [a]
deriving ( Eq, Ord, Show, Read, Data, Generic, Generic1 )
+-- | @since 4.10.0.0
+instance Eq1 NonEmpty where
+ liftEq eq (a :| as) (b :| bs) = eq a b && liftEq eq as bs
+
+-- | @since 4.10.0.0
+instance Ord1 NonEmpty where
+ liftCompare cmp (a :| as) (b :| bs) = cmp a b <> liftCompare cmp as bs
+
+-- | @since 4.10.0.0
+instance Read1 NonEmpty where
+ liftReadsPrec rdP rdL p s = readParen (p > 5) (\s' -> do
+ (a, s'') <- rdP 6 s'
+ (":|", s''') <- lex s''
+ (as, s'''') <- rdL s'''
+ return (a :| as, s'''')) s
+
+-- | @since 4.10.0.0
+instance Show1 NonEmpty where
+ liftShowsPrec shwP shwL p (a :| as) = showParen (p > 5) $
+ shwP 6 a . showString " :| " . shwL as
+
-- | @since 4.9.0.0
instance Exts.IsList (NonEmpty a) where
type Item (NonEmpty a) = a
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index dcc1719..5983747 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -28,6 +28,8 @@
* Add `Data` instance for `Const` (#12438)
+ * Added `Eq1`, `Ord1`, `Read1` and `Show1` instances for `NonEmpty`.
+
## 4.9.0.0 *May 2016*
* Bundled with GHC 8.0
More information about the ghc-commits
mailing list