diff options
author | Shane <shane@duairc.com> | 2016-11-29 17:53:44 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-11-29 18:46:33 -0500 |
commit | b92f8e38b1d58bef55b4fec67c1f0807e960512d (patch) | |
tree | caf87792f3cf83a804a2f90f819f019d933faab2 /libraries | |
parent | 23dc6c459b61b400c7140ffc49b3b8b45a4a1159 (diff) | |
download | haskell-b92f8e38b1d58bef55b4fec67c1f0807e960512d.tar.gz |
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
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Data/List/NonEmpty.hs | 23 | ||||
-rw-r--r-- | libraries/base/changelog.md | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/libraries/base/Data/List/NonEmpty.hs b/libraries/base/Data/List/NonEmpty.hs index 1cba3e5301..b4da532b1d 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 dcc171979f..5983747a96 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 |