1
1
module Control.Monad
2
2
( class Monad
3
3
, liftM1
4
- , ap
5
4
, whenM
6
5
, unlessM
7
6
, module Data.Functor
@@ -12,7 +11,7 @@ module Control.Monad
12
11
13
12
import Control.Applicative (class Applicative , liftA1 , pure , unless , when )
14
13
import Control.Apply (class Apply , apply , (*>), (<*), (<*>))
15
- import Control.Bind (class Bind , bind , ifM , join , (<=<), (=<<), (>=>), (>>=))
14
+ import Control.Bind (class Bind , bind , ap , ifM , join , (<=<), (=<<), (>=>), (>>=))
16
15
17
16
import Data.Functor (class Functor , map , void , ($>), (<#>), (<$), (<$>))
18
17
import Data.Unit (Unit )
@@ -27,7 +26,6 @@ import Data.Unit (Unit)
27
26
-- |
28
27
-- | - Left Identity: `pure x >>= f = f x`
29
28
-- | - Right Identity: `x >>= pure = x`
30
- -- | - Applicative Superclass: `apply = ap`
31
29
class (Applicative m , Bind m ) <= Monad m
32
30
33
31
instance monadFn :: Monad ((-> ) r )
@@ -50,23 +48,6 @@ liftM1 f a = do
50
48
a' <- a
51
49
pure (f a')
52
50
53
- -- | `ap` provides a default implementation of `(<*>)` for any
54
- -- | [`Monad`](#monad), without using `(<*>)` as provided by the
55
- -- | [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
56
- -- |
57
- -- | `ap` can therefore be used to write [`Apply`](#apply) instances as
58
- -- | follows:
59
- -- |
60
- -- | ```purescript
61
- -- | instance applyF :: Apply F where
62
- -- | apply = ap
63
- -- | ```
64
- ap :: forall m a b . Monad m => m (a -> b ) -> m a -> m b
65
- ap f a = do
66
- f' <- f
67
- a' <- a
68
- pure (f' a')
69
-
70
51
-- | Perform a monadic action when a condition is true, where the conditional
71
52
-- | value is also in a monadic context.
72
53
whenM :: forall m . Monad m => m Boolean -> m Unit -> m Unit
0 commit comments