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: 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.