Skip to content

Commit f6b5294

Browse files
authored
Add Semiring instance (#59)
* Add Semiring instance * Update CHANGELOG.md
1 parent 8e96ca0 commit f6b5294

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

99
New features:
10+
- Added `Semiring` instance (#59)
1011

1112
Bugfixes:
1213

src/Data/Maybe.purs

+10
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ instance semigroupMaybe :: Semigroup a => Semigroup (Maybe a) where
190190
instance monoidMaybe :: Semigroup a => Monoid (Maybe a) where
191191
mempty = Nothing
192192

193+
instance semiringMaybe :: Semiring a => Semiring (Maybe a) where
194+
zero = Nothing
195+
one = Just one
196+
197+
add Nothing y = y
198+
add x Nothing = x
199+
add (Just x) (Just y) = Just (add x y)
200+
201+
mul x y = mul <$> x <*> y
202+
193203
-- | The `Eq` instance allows `Maybe` values to be checked for equality with
194204
-- | `==` and inequality with `/=` whenever there is an `Eq` instance for the
195205
-- | type the `Maybe` contains.

0 commit comments

Comments
 (0)