Skip to content

Commit

Permalink
Merge pull request #43 from input-output-hk/coot/monoids
Browse files Browse the repository at this point in the history
Monoids & Semigroups
  • Loading branch information
coot authored Jan 25, 2024
2 parents 4fa4758 + ff52412 commit 9ae9e18
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## next version

* `NoThunks` instances for `Data.Semigroup` and `Data.Monoid` newtype wrappers.

## 0.1.5 -- 2023-10-29

* `NoThunks ThreadId` instance.
Expand Down
29 changes: 28 additions & 1 deletion src/NoThunks/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ import qualified Data.IntMap as IntMap
import qualified Data.IORef as IORef
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Monoid as Monoid
import qualified Data.Semigroup as Semigroup

#ifdef MIN_VERSION_bytestring
import Data.ByteString.Short (ShortByteString)
Expand Down Expand Up @@ -381,7 +383,7 @@ instance GWNoThunks a f => GWNoThunks a (D1 c f) where
instance GWNoThunks a f => GWNoThunks a (C1 c f) where
gwNoThunks a ctxt (M1 fp) = gwNoThunks a ctxt fp

instance GWNoThunks a f => GWNoThunks a (S1 ('MetaSel ('Nothing) su ss ds) f) where
instance GWNoThunks a f => GWNoThunks a (S1 ('MetaSel 'Nothing su ss ds) f) where
gwNoThunks a ctxt (M1 fp) = gwNoThunks a ctxt fp

instance (GWNoThunks a f, GWNoThunks a g) => GWNoThunks a (f :*: g) where
Expand Down Expand Up @@ -479,6 +481,31 @@ deriving via OnlyCheckWhnf Word16 instance NoThunks Word16
deriving via OnlyCheckWhnf Word32 instance NoThunks Word32
deriving via OnlyCheckWhnf Word64 instance NoThunks Word64

{-------------------------------------------------------------------------------
Semigroups
-------------------------------------------------------------------------------}

deriving via a instance NoThunks a => NoThunks (Semigroup.Min a)
deriving via a instance NoThunks a => NoThunks (Semigroup.Max a)
deriving via a instance NoThunks a => NoThunks (Semigroup.First a)
deriving via a instance NoThunks a => NoThunks (Semigroup.Last a)
deriving via a instance NoThunks a => NoThunks (Semigroup.Dual a)
deriving via Bool instance NoThunks Semigroup.All
deriving via Bool instance NoThunks Semigroup.Any
deriving via a instance NoThunks a => NoThunks (Semigroup.Sum a)
deriving via a instance NoThunks a => NoThunks (Semigroup.Product a)
deriving via a instance NoThunks a => NoThunks (Semigroup.WrappedMonoid a)
instance (NoThunks a, NoThunks b) => NoThunks (Semigroup.Arg a b)

{-------------------------------------------------------------------------------
Monoids
-------------------------------------------------------------------------------}

deriving via (Maybe a) instance NoThunks a => NoThunks (Monoid.First a)
deriving via (Maybe a) instance NoThunks a => NoThunks (Monoid.Last a)
deriving via (f a) instance NoThunks (f a) => NoThunks (Monoid.Alt f a)
deriving via (f a) instance NoThunks (f a) => NoThunks (Monoid.Ap f a)

{-------------------------------------------------------------------------------
Mutable Vars
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit 9ae9e18

Please sign in to comment.