diff options
Diffstat (limited to 'libraries/base')
-rw-r--r-- | libraries/base/Data/Functor/Compose.hs | 3 | ||||
-rw-r--r-- | libraries/base/Data/Functor/Product.hs | 8 | ||||
-rw-r--r-- | libraries/base/changelog.md | 3 |
3 files changed, 14 insertions, 0 deletions
diff --git a/libraries/base/Data/Functor/Compose.hs b/libraries/base/Data/Functor/Compose.hs index e0879acdad..97ad997691 100644 --- a/libraries/base/Data/Functor/Compose.hs +++ b/libraries/base/Data/Functor/Compose.hs @@ -1,6 +1,7 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE Trustworthy #-} @@ -42,6 +43,8 @@ newtype Compose f g a = Compose { getCompose :: f (g a) } deriving ( Data -- ^ @since 4.9.0.0 , Generic -- ^ @since 4.9.0.0 , Generic1 -- ^ @since 4.9.0.0 + , Semigroup -- ^ @since 4.16.0.0 + , Monoid -- ^ @since 4.16.0.0 ) -- Instances of lifted Prelude classes diff --git a/libraries/base/Data/Functor/Product.hs b/libraries/base/Data/Functor/Product.hs index a3678e910e..27e3b3a9f8 100644 --- a/libraries/base/Data/Functor/Product.hs +++ b/libraries/base/Data/Functor/Product.hs @@ -124,3 +124,11 @@ instance (MonadFix f, MonadFix g) => MonadFix (Product f g) where -- | @since 4.9.0.0 instance (MonadZip f, MonadZip g) => MonadZip (Product f g) where mzipWith f (Pair x1 y1) (Pair x2 y2) = Pair (mzipWith f x1 x2) (mzipWith f y1 y2) + +-- | @since 4.16.0.0 +instance (Semigroup (f a), Semigroup (g a)) => Semigroup (Product f g a) where + Pair x1 y1 <> Pair x2 y2 = Pair (x1 <> x2) (y1 <> y2) + +-- | @since 4.16.0.0 +instance (Monoid (f a), Monoid (g a)) => Monoid (Product f g a) where + mempty = Pair mempty mempty diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index 197388a652..95face49e9 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -8,6 +8,9 @@ in order to define instances for `Nat`. Also, different instances for `Nat` and `Natural` won't typecheck anymore. + * Add `Semigroup` and `Monoid` instances for `Data.Functor.Product` and + `Data.Functor.Compose`. + ## 4.15.0.0 *TBA* * `openFile` now calls the `open` system call with an `interruptible` FFI |