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
+
1
11
module Control.MonadZero
2
12
( class MonadZero
3
- , guard
4
13
, module Control.Alt
5
14
, module Control.Alternative
6
15
, module Control.Applicative
@@ -12,15 +21,16 @@ module Control.MonadZero
12
21
) where
13
22
14
23
import Control.Alt (class Alt , alt , (<|>))
15
- import Control.Alternative (class Alternative )
24
+ import Control.Alternative (class Alternative , guard )
16
25
import Control.Applicative (class Applicative , pure , liftA1 , unless , when )
17
26
import Control.Apply (class Apply , apply , (*>), (<*), (<*>))
18
27
import Control.Bind (class Bind , bind , ifM , join , (<=<), (=<<), (>=>), (>>=))
19
28
import Control.Monad (class Monad , ap , liftM1 )
20
29
import Control.Plus (class Plus , empty )
21
30
22
31
import Data.Functor (class Functor , map , void , ($>), (<#>), (<$), (<$>))
23
- import Data.Unit (Unit , unit )
32
+
33
+ import Prim.TypeError (class Warn , Text )
24
34
25
35
-- | The `MonadZero` type class has no members of its own; it just specifies
26
36
-- | that the type has both `Monad` and `Alternative` instances.
@@ -29,28 +39,4 @@ import Data.Unit (Unit, unit)
29
39
-- | laws:
30
40
-- |
31
41
-- | - 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