Skip to content

Commit 7abb455

Browse files
committed
More Alt and Plus laws
1 parent b38b04a commit 7abb455

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ It is similar to `Semigroup`, except that it applies to types of
1414
kind `* -> *`, like `Array` or `List`, rather than concrete types like
1515
`String` or `Number`.
1616

17-
`Alt` instances are required to satisfy the following law:
17+
`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)`
2021

2122
For example, the `Array` (`[]`) type is an instance of `Alt`, where
2223
`(<|>)` is defined to be concatenation.
@@ -318,10 +319,12 @@ class (Alt f) <= Plus f where
318319
The `Plus` type class extends the `Alt` type class with a value that
319320
should be the left and right identity for `(<|>)`.
320321
It is similar to `Monoid`, except that it applies to types of
321-
kind (* -> *), like `Array` or `List`, rather than concrete types like
322+
kind `* -> *`, like `Array` or `List`, rather than concrete types like
322323
`String` or `Number`.
323324

324325
`Plus` instances should satisfy the following laws:
325326

326327
- Left identity: `empty <|> x == x`
327-
- Right identity: `x <|> empty == x`
328+
- Right identity: `x <|> empty == x`
329+
- ???: `f <$> empty == empty`
330+
- Left distribution: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`

src/Control/Alt.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ infixl 3 <|>
77
-- | kind `* -> *`, like `Array` or `List`, rather than concrete types like
88
-- | `String` or `Number`.
99
-- |
10-
-- | `Alt` instances are required to satisfy the following law:
10+
-- | `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)`
1314
-- |
1415
-- | For example, the `Array` (`[]`) type is an instance of `Alt`, where
1516
-- | `(<|>)` is defined to be concatenation.

src/Control/Plus.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ import Control.Alt
1212
-- |
1313
-- | - Left identity: `empty <|> x == x`
1414
-- | - Right identity: `x <|> empty == x`
15+
-- | - ???: `f <$> empty == empty`
16+
-- | - Left distribution: `(x <|> y) >>= f == (x >>= f) <|> (y >>= f)`
1517
class (Alt f) <= Plus f where
1618
empty :: forall a. f a

0 commit comments

Comments
 (0)