Commit b92f8e38 authored by duairc's avatar duairc Committed by Ben Gamari
Browse files

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
parent 23dc6c45
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment