diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..59c7d3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Revision history for `interval-functor`. + +## `0.1.0.0` — Sunday, 13 of September 2020. + +* Add instances `Show1`, `Eq1`, `Ord1`. + +## `0.0.0.0` — Saturday, 11 of July 2020. + +* First version. Released on an unsuspecting world. diff --git a/interval-functor.cabal b/interval-functor.cabal index 3445b18..fadc893 100644 --- a/interval-functor.cabal +++ b/interval-functor.cabal @@ -1,7 +1,7 @@ cabal-version: 2.2 name: interval-functor -version: 0.0.0.0 +version: 0.1.0.0 synopsis: Intervals of functors. description: Closed intervals in spaces described by a functor. homepage: https://github.com/robrix/interval-functor @@ -50,6 +50,8 @@ library build-depends: , base >= 4.10 && < 5 , transformers ^>= 0.5.6.2 + , generic-data ^>= 0.9 + , deepseq ^>=1.4 hs-source-dirs: src test-suite test diff --git a/src/Data/Functor/Interval.hs b/src/Data/Functor/Interval.hs index 88693ab..03a912c 100644 --- a/src/Data/Functor/Interval.hs +++ b/src/Data/Functor/Interval.hs @@ -52,11 +52,14 @@ module Data.Functor.Interval ) where import Control.Applicative (liftA2) +import Control.DeepSeq (NFData) import Control.Monad.Trans.Class import Data.Coerce (coerce) import Data.Fixed (mod') import Data.Function (on) +import Data.Functor.Classes (Show1, liftShowsPrec, Eq1, liftEq, Ord1, liftCompare) import Data.Semigroup +import Generic.Data (gliftShowsPrec) import GHC.Generics (Generic, Generic1) -- | @f@-dimensional intervals with coordinates in @a@. @@ -78,6 +81,21 @@ instance Show (f a) => Show (Interval f a) where showsPrec p i = showParen (p > 3) $ showsPrec 4 (inf i) . showString "..." . showsPrec 4 (sup i) {-# INLINE showsPrec #-} +instance Show1 f => Show1 (Interval f) where + liftShowsPrec = gliftShowsPrec + +instance Eq1 f => Eq1 (Interval f) where + liftEq f (Interval u v) (Interval u' v') = case liftEq f u u' of + True -> liftEq f v v' + False -> False + +instance Ord1 f => Ord1 (Interval f) where + liftCompare f (Interval u v) (Interval u' v') = case liftCompare f u u' of + EQ -> liftCompare f v v' + x -> x + +instance NFData (f a) => NFData (Interval f a) + instance Applicative f => Applicative (Interval f) where pure = point . pure {-# INLINE pure #-}