1+ -- | This module is **deprecated** and will be removed in a future release.
2+ -- |
3+ -- | The annihilation law witnessed by `MonadZero` is trivially satisfied by
4+ -- | lawful monads due to parametricity: while evaluating `empty >>= f`, the
5+ -- | function `f` can’t ever be called, since that would require `empty` to
6+ -- | produce a value, which means that `empty >>= f` must be the same as
7+ -- | `empty >>= pure`, which by the monad laws is just `empty`.
8+ -- |
9+ -- | Use `Monad` and `Alternative` constraints instead.
10+
111module Control.MonadZero
212 ( class MonadZero
3- , guard
413 , module Control.Alt
514 , module Control.Alternative
615 , module Control.Applicative
@@ -12,15 +21,16 @@ module Control.MonadZero
1221 ) where
1322
1423import Control.Alt (class Alt , alt , (<|>))
15- import Control.Alternative (class Alternative )
24+ import Control.Alternative (class Alternative , guard )
1625import Control.Applicative (class Applicative , pure , liftA1 , unless , when )
1726import Control.Apply (class Apply , apply , (*>), (<*), (<*>))
1827import Control.Bind (class Bind , bind , ifM , join , (<=<), (=<<), (>=>), (>>=))
1928import Control.Monad (class Monad , ap , liftM1 )
2029import Control.Plus (class Plus , empty )
2130
2231import Data.Functor (class Functor , map , void , ($>), (<#>), (<$), (<$>))
23- import Data.Unit (Unit , unit )
32+
33+ import Prim.TypeError (class Warn , Text )
2434
2535-- | The `MonadZero` type class has no members of its own; it just specifies
2636-- | that the type has both `Monad` and `Alternative` instances.
@@ -29,28 +39,4 @@ import Data.Unit (Unit, unit)
2939-- | laws:
3040-- |
3141-- | - Annihilation: `empty >>= f = empty`
32- class (Monad m , Alternative m ) <= MonadZero m
33-
34- instance monadZeroArray :: MonadZero Array
35-
36- -- | Fail using `Plus` if a condition does not hold, or
37- -- | succeed using `Monad` if it does.
38- -- |
39- -- | For example:
40- -- |
41- -- | ```purescript
42- -- | import Prelude
43- -- | import Control.Monad (bind)
44- -- | import Control.MonadZero (guard)
45- -- | import Data.Array ((..))
46- -- |
47- -- | factors :: Int -> Array Int
48- -- | factors n = do
49- -- | a <- 1..n
50- -- | b <- 1..n
51- -- | guard $ a * b == n
52- -- | pure a
53- -- | ```
54- guard :: forall m . MonadZero m => Boolean -> m Unit
55- guard true = pure unit
56- guard false = empty
42+ class (Monad m , Alternative m , Warn (Text " 'MonadZero' is deprecated, use 'Monad' and 'Alternative' constraints instead" )) <= MonadZero m
0 commit comments