Skip to content

Commit 0c93f9e

Browse files
committed
More docs updates for Alt, Plus, MonadPlus
1 parent dbb7ea7 commit 0c93f9e

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ For example, the `Array` (`[]`) type is an instance of `Alt`, where
3131
class (Applicative f, Plus f) <= Alternative f where
3232
```
3333

34+
The `Alternative` type class has no members of its own; it just specifies
35+
that the type has both `Applicative` and `Plus` instances.
36+
37+
Types which have `Alternative` instances should also satisfy the following
38+
laws:
39+
40+
- Distributivity: `(f <|> g) <*> x == (f <*> x) <|> (g <*> x)`
41+
- Annihilation: `empty <*> f = empty`
3442

3543
#### `some`
3644

@@ -298,13 +306,14 @@ unless :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
298306
class (Monad m, Alternative m) <= MonadPlus m where
299307
```
300308

301-
The `MonadPlus` type class has none of its own functions; it just
302-
specifies that the type has both `Monad` and `Alternative` instances.
309+
The `MonadPlus` type class has no members of its own; it just specifies
310+
that the type has both `Monad` and `Alternative` instances.
303311

304312
Types which have `MonadPlus` instances should also satisfy the following
305-
law:
313+
laws:
306314

307-
- Left distributivity: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`
315+
- Distributivity: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`
316+
- Annihilation: `empty >>= f = empty`
308317

309318
#### `guard`
310319

@@ -333,4 +342,4 @@ kind `* -> *`, like `Array` or `List`, rather than concrete types like
333342

334343
- Left identity: `empty <|> x == x`
335344
- Right identity: `x <|> empty == x`
336-
- ???: `f <$> empty == empty`
345+
- Annihilation: `f <$> empty == empty`

src/Control/Alternative.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import Control.Alt
44
import Control.Lazy
55
import Control.Plus
66

7+
-- | The `Alternative` type class has no members of its own; it just specifies
8+
-- | that the type has both `Applicative` and `Plus` instances.
9+
-- |
10+
-- | Types which have `Alternative` instances should also satisfy the following
11+
-- | laws:
12+
-- |
13+
-- | - Distributivity: `(f <|> g) <*> x == (f <*> x) <|> (g <*> x)`
14+
-- | - Annihilation: `empty <*> f = empty`
715
class (Applicative f, Plus f) <= Alternative f
816

917
some :: forall f a. (Alternative f, Lazy1 f) => f a -> f [a]

src/Control/MonadPlus.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ module Control.MonadPlus where
33
import Control.Alternative
44
import Control.Plus
55

6-
-- | The `MonadPlus` type class has none of its own functions; it just
7-
-- | specifies that the type has both `Monad` and `Alternative` instances.
6+
-- | The `MonadPlus` type class has no members of its own; it just specifies
7+
-- | that the type has both `Monad` and `Alternative` instances.
88
-- |
99
-- | Types which have `MonadPlus` instances should also satisfy the following
10-
-- | law:
10+
-- | laws:
1111
-- |
12-
-- | - Left distributivity: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`
12+
-- | - Distributivity: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`
13+
-- | - Annihilation: `empty >>= f = empty`
1314
class (Monad m, Alternative m) <= MonadPlus m
1415

1516
guard :: forall m. (MonadPlus m) => Boolean -> m Unit

src/Control/Plus.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ import Control.Alt
1212
-- |
1313
-- | - Left identity: `empty <|> x == x`
1414
-- | - Right identity: `x <|> empty == x`
15-
-- | - ???: `f <$> empty == empty`
15+
-- | - Annihilation: `f <$> empty == empty`
1616
class (Alt f) <= Plus f where
1717
empty :: forall a. f a

0 commit comments

Comments
 (0)