Skip to content

Commit dbb7ea7

Browse files
committed
More docs for Alt, Plus, MonadPlus
1 parent 7abb455 commit dbb7ea7

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ kind `* -> *`, like `Array` or `List`, rather than concrete types like
1717
`Alt` instances are required to satisfy the following laws:
1818

1919
- Associativity: `(x <|> y) <|> z == x <|> (y <|> z)`
20-
- Distribution: `f <$> (x <|> y) == (f <$> x) <|> (f <$> y)`
20+
- Distributivity: `f <$> (x <|> y) == (f <$> x) <|> (f <$> y)`
2121

2222
For example, the `Array` (`[]`) type is an instance of `Alt`, where
2323
`(<|>)` is defined to be concatenation.
@@ -298,6 +298,13 @@ unless :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
298298
class (Monad m, Alternative m) <= MonadPlus m where
299299
```
300300

301+
The `MonadPlus` type class has none of its own functions; it just
302+
specifies that the type has both `Monad` and `Alternative` instances.
303+
304+
Types which have `MonadPlus` instances should also satisfy the following
305+
law:
306+
307+
- Left distributivity: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`
301308

302309
#### `guard`
303310

@@ -326,5 +333,4 @@ kind `* -> *`, like `Array` or `List`, rather than concrete types like
326333

327334
- Left identity: `empty <|> x == x`
328335
- Right identity: `x <|> empty == x`
329-
- ???: `f <$> empty == empty`
330-
- Left distribution: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`
336+
- ???: `f <$> empty == empty`

src/Control/Alt.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ infixl 3 <|>
1010
-- | `Alt` instances are required to satisfy the following laws:
1111
-- |
1212
-- | - Associativity: `(x <|> y) <|> z == x <|> (y <|> z)`
13-
-- | - Distribution: `f <$> (x <|> y) == (f <$> x) <|> (f <$> y)`
13+
-- | - Distributivity: `f <$> (x <|> y) == (f <$> x) <|> (f <$> y)`
1414
-- |
1515
-- | For example, the `Array` (`[]`) type is an instance of `Alt`, where
1616
-- | `(<|>)` is defined to be concatenation.

src/Control/MonadPlus.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ 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.
8+
-- |
9+
-- | Types which have `MonadPlus` instances should also satisfy the following
10+
-- | law:
11+
-- |
12+
-- | - Left distributivity: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`
613
class (Monad m, Alternative m) <= MonadPlus m
714

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

src/Control/Plus.purs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ import Control.Alt
1313
-- | - Left identity: `empty <|> x == x`
1414
-- | - Right identity: `x <|> empty == x`
1515
-- | - ???: `f <$> empty == empty`
16-
-- | - Left distribution: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`
1716
class (Alt f) <= Plus f where
1817
empty :: forall a. f a

0 commit comments

Comments
 (0)