@@ -204,19 +204,27 @@ instance invariantFirst :: Invariant Maybe where
204
204
-- | Nothing <> Nothing = Nothing
205
205
-- | ```
206
206
instance semigroupMaybe :: (Semigroup a ) => Semigroup (Maybe a ) where
207
- append Nothing x = x
208
- append x Nothing = x
209
- append (Just x) (Just y) = Just (x <> y)
207
+ append x y = append <$> x <*> y
210
208
211
209
instance monoidMaybe :: (Semigroup a ) => Monoid (Maybe a ) where
212
210
mempty = Nothing
213
211
214
- -- | The `Show` instance allows `Maybe` values to be rendered as a string with
215
- -- | `show` whenever there is an `Show` instance for the type the `Maybe`
216
- -- | contains.
217
- instance showMaybe :: (Show a ) => Show (Maybe a ) where
218
- show (Just x) = " Just (" ++ show x ++ " )"
219
- show Nothing = " Nothing"
212
+ instance semiringMaybe :: (Semiring a ) => Semiring (Maybe a ) where
213
+ add x y = add <$> x <*> y
214
+ one = Just one
215
+ mul x y = mul <$> x <*> y
216
+ zero = Just zero
217
+
218
+ instance moduloSemiringMaybe :: (ModuloSemiring a ) => ModuloSemiring (Maybe a ) where
219
+ mod x y = mod <$> x <*> y
220
+ div x y = div <$> x <*> y
221
+
222
+ instance ringMaybe :: (Ring a ) => Ring (Maybe a ) where
223
+ sub x y = sub <$> x <*> y
224
+
225
+ instance divisionRingMaybe :: (DivisionRing a ) => DivisionRing (Maybe a )
226
+
227
+ instance numMaybe :: (Num a ) => Num (Maybe a )
220
228
221
229
-- | The `Eq` instance allows `Maybe` values to be checked for equality with
222
230
-- | `==` and inequality with `/=` whenever there is an `Eq` instance for the
@@ -240,3 +248,17 @@ instance ordMaybe :: (Ord a) => Ord (Maybe a) where
240
248
instance boundedMaybe :: (Bounded a ) => Bounded (Maybe a ) where
241
249
top = Just top
242
250
bottom = Nothing
251
+
252
+ instance boundedOrdMaybe :: (BoundedOrd a ) => BoundedOrd (Maybe a )
253
+
254
+ instance booleanAlgebraMaybe :: (BooleanAlgebra a ) => BooleanAlgebra (Maybe a ) where
255
+ conj x y = conj <$> x <*> y
256
+ disj x y = disj <$> x <*> y
257
+ not = map not
258
+
259
+ -- | The `Show` instance allows `Maybe` values to be rendered as a string with
260
+ -- | `show` whenever there is an `Show` instance for the type the `Maybe`
261
+ -- | contains.
262
+ instance showMaybe :: (Show a ) => Show (Maybe a ) where
263
+ show (Just x) = " Just (" ++ show x ++ " )"
264
+ show Nothing = " Nothing"
0 commit comments