From 1baefa5bd947078f52dc35f0aa58be55cd54ce52 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Thu, 2 Mar 2017 23:19:10 +0000 Subject: [PATCH] Add `Eq1` and `Ord1` instances --- bower.json | 3 ++- src/Data/Maybe.purs | 6 ++++++ src/Data/Maybe/First.purs | 6 ++++++ src/Data/Maybe/Last.purs | 6 ++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 2839faa..b45fa77 100644 --- a/bower.json +++ b/bower.json @@ -17,6 +17,7 @@ "package.json" ], "dependencies": { - "purescript-monoid": "^2.0.0" + "purescript-monoid": "^2.2.0", + "purescript-prelude": "^2.4.0" } } diff --git a/src/Data/Maybe.purs b/src/Data/Maybe.purs index a586558..fb27fe8 100644 --- a/src/Data/Maybe.purs +++ b/src/Data/Maybe.purs @@ -8,8 +8,10 @@ import Control.Extend (class Extend) import Control.MonadZero (class MonadZero) import Control.Plus (class Plus) +import Data.Eq (class Eq1) import Data.Functor.Invariant (class Invariant, imapF) import Data.Monoid (class Monoid) +import Data.Ord (class Ord1) -- | The `Maybe` type is used to represent optional values and can be seen as -- | something like a type-safe `null`, where `Nothing` is `null` and `Just x` @@ -184,6 +186,8 @@ instance monoidMaybe :: Semigroup a => Monoid (Maybe a) where -- | type the `Maybe` contains. derive instance eqMaybe :: Eq a => Eq (Maybe a) +instance eq1Maybe :: Eq1 Maybe where eq1 = eq + -- | The `Ord` instance allows `Maybe` values to be compared with -- | `compare`, `>`, `>=`, `<` and `<=` whenever there is an `Ord` instance for -- | the type the `Maybe` contains. @@ -191,6 +195,8 @@ derive instance eqMaybe :: Eq a => Eq (Maybe a) -- | `Nothing` is considered to be less than any `Just` value. derive instance ordMaybe :: Ord a => Ord (Maybe a) +instance ord1Maybe :: Ord1 Maybe where compare1 = compare + instance boundedMaybe :: Bounded a => Bounded (Maybe a) where top = Just top bottom = Nothing diff --git a/src/Data/Maybe/First.purs b/src/Data/Maybe/First.purs index f346c6d..74a4105 100644 --- a/src/Data/Maybe/First.purs +++ b/src/Data/Maybe/First.purs @@ -4,10 +4,12 @@ import Prelude import Control.Extend (class Extend) +import Data.Eq (class Eq1) import Data.Functor.Invariant (class Invariant) import Data.Maybe (Maybe(..)) import Data.Monoid (class Monoid) import Data.Newtype (class Newtype) +import Data.Ord (class Ord1) -- | Monoid returning the first (left-most) non-`Nothing` value. -- | @@ -23,8 +25,12 @@ derive instance newtypeFirst :: Newtype (First a) _ derive newtype instance eqFirst :: (Eq a) => Eq (First a) +derive newtype instance eq1First :: Eq1 First + derive newtype instance ordFirst :: (Ord a) => Ord (First a) +derive newtype instance ord1First :: Ord1 First + derive newtype instance boundedFirst :: (Bounded a) => Bounded (First a) derive newtype instance functorFirst :: Functor First diff --git a/src/Data/Maybe/Last.purs b/src/Data/Maybe/Last.purs index 9383a46..b719fac 100644 --- a/src/Data/Maybe/Last.purs +++ b/src/Data/Maybe/Last.purs @@ -4,10 +4,12 @@ import Prelude import Control.Extend (class Extend) +import Data.Eq (class Eq1) import Data.Functor.Invariant (class Invariant) import Data.Maybe (Maybe(..)) import Data.Monoid (class Monoid) import Data.Newtype (class Newtype) +import Data.Ord (class Ord1) -- | Monoid returning the last (right-most) non-`Nothing` value. -- | @@ -23,8 +25,12 @@ derive instance newtypeLast :: Newtype (Last a) _ derive newtype instance eqLast :: (Eq a) => Eq (Last a) +derive newtype instance eq1Last :: Eq1 Last + derive newtype instance ordLast :: (Ord a) => Ord (Last a) +derive newtype instance ord1Last :: Ord1 Last + derive newtype instance boundedLast :: (Bounded a) => Bounded (Last a) derive newtype instance functorLast :: Functor Last