Skip to content

Commit

Permalink
Backport instances introduced in base-4.20
Browse files Browse the repository at this point in the history
Fixes #71.
  • Loading branch information
RyanGlScott committed Apr 30, 2024
1 parent 5e6b2c1 commit eedfc38
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Changes in next [????.??.??]
- Backport new instances from GHC 9.10/`base-4.20`:
* `Fractional`, `RealFrac`, `Floating`, and `RealFloat` instances for `Compose`

## Changes in 0.9.1 [2023.10.11]
- Backport new instances from GHC 9.8/`base-4.19`:
* `Eq` and `Ord` instances for `SChar`, `SNat`, and `SSymbol`
Expand Down
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ To use `base-orphans`, simply `import Data.Orphans ()`.
* `Eq` and `Ord` instances for `SChar`, `SNat`, and `SSymbol`
* `Eq1`, `Read1`, and `Show1` instances for `Complex`
* `Eq1`, `Ord1`, `Read1`, and `Show1` instances for `NonEmpty`
* `Enum`, `Bounded`, `Num`, `Real`, and `Integral` instances for `Compose`
* `Enum`, `Bounded`, `Num`, `Real`, `Integral`, `Fractional`, `RealFrac`, `Floating`, and `RealFloat` instances for `Compose`
* `Foldable` instance for `Either`, `(,)` and `Const`
* `Foldable` and `Traversable` instances for `Alt` from `Data.Monoid`
* `Functor`, `Applicative`, and `Monad` instances for
Expand Down Expand Up @@ -106,6 +106,7 @@ To use `base-orphans`, simply `import Data.Orphans ()`.

## Supported versions of GHC/`base`

* `ghc-9.10.*` / `base-4.20.*`
* `ghc-9.8.*` / `base-4.19.*`
* `ghc-9.6.*` / `base-4.18.*`
* `ghc-9.4.*` / `base-4.17.*`
Expand Down
21 changes: 20 additions & 1 deletion src/Data/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import GHC.ConsoleHandler as Console
# endif
#endif

#if !(MIN_VERSION_base(4,19,0))
#if !(MIN_VERSION_base(4,20,0))
import Data.Orphans.Prelude
#endif

Expand Down Expand Up @@ -2050,6 +2050,25 @@ instance Ord (SSymbol s) where
# endif
#endif

#if !(MIN_VERSION_base(4,20,0))
# if MIN_VERSION_base(4,9,0)
deriving instance Fractional (f (g a)) => Fractional (Compose f g a)
deriving instance Floating (f (g a)) => Floating (Compose f g a)

-- RealFrac and RealFloat both have Ord as a superclass. For the reasons stated
-- above (near the Real/Integral instances for Compose), these
-- RealFrace/RealFloat instances are slightly more complicated for older
-- versions of base.
# if MIN_VERSION_base(4,18,0)
deriving instance RealFrac (f (g a)) => RealFrac (Compose f g a)
deriving instance RealFloat (f (g a)) => RealFloat (Compose f g a)
# else
deriving instance (RealFrac (f (g a)), Ord1 f, Ord1 g, Ord a) => RealFrac (Compose f g a)
deriving instance (RealFloat (f (g a)), Ord1 f, Ord1 g, Ord a) => RealFloat (Compose f g a)
# endif
# endif
#endif

#if __GLASGOW_HASKELL__ < 710
deriving instance Typeable All
deriving instance Typeable AnnotationWrapper
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Orphans/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This makes it much easier to be -Wall-compliant.
Note that this module does not export any modules that could introduce name clashes.
-}
module Data.Orphans.Prelude
#if MIN_VERSION_base(4,19,0)
#if MIN_VERSION_base(4,20,0)
() where
#else
( module OrphansPrelude
Expand Down

0 comments on commit eedfc38

Please sign in to comment.