From efa00f3e0bf902732154961254f05faeade7249c Mon Sep 17 00:00:00 2001 From: Berk Ozkutuk Date: Sat, 6 Nov 2021 20:51:06 +0300 Subject: [PATCH 1/2] Add Semiring instance --- src/Data/Maybe.purs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Data/Maybe.purs b/src/Data/Maybe.purs index 3bf9891..9c80c05 100644 --- a/src/Data/Maybe.purs +++ b/src/Data/Maybe.purs @@ -190,6 +190,16 @@ instance semigroupMaybe :: Semigroup a => Semigroup (Maybe a) where instance monoidMaybe :: Semigroup a => Monoid (Maybe a) where mempty = Nothing +instance semiringMaybe :: Semiring a => Semiring (Maybe a) where + zero = Nothing + one = Just one + + add Nothing y = y + add x Nothing = x + add (Just x) (Just y) = Just (add x y) + + mul x y = mul <$> x <*> y + -- | The `Eq` instance allows `Maybe` values to be checked for equality with -- | `==` and inequality with `/=` whenever there is an `Eq` instance for the -- | type the `Maybe` contains. From 8415e270b079fbb967bfaaf9f165e7e340529ba1 Mon Sep 17 00:00:00 2001 From: Berk Ozkutuk Date: Sat, 6 Nov 2021 21:06:57 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f214920..3f75361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based Breaking changes: New features: +- Added `Semiring` instance (#59) Bugfixes: