Add spec for Alt, Plus, Alternative
See original GitHub issueI think it would be nice if we also define algebras for Alt
, Plus
and Alternative
-- | The `Alt` type class identifies an associative operation on a type
-- | constructor. It is similar to `Semigroup`, except that it applies to
-- | types of kind `* -> *`, like `Array` or `List`, rather than concrete types
-- | `String` or `Number`.
-- |
-- | `Alt` instances are required to satisfy the following laws:
-- |
-- | - Associativity: `(x <|> y) <|> z == x <|> (y <|> z)`
-- | - Distributivity: `f <$> (x <|> y) == (f <$> x) <|> (f <$> y)`
-- |
-- | For example, the `Array` (`[]`) type is an instance of `Alt`, where
-- | `(<|>)` is defined to be concatenation.
class Functor f <= Alt f where
alt :: forall a. f a -> f a -> f a
-- | The `Plus` type class extends the `Alt` type class with a value that
-- | should be the left and right identity for `(<|>)`.
-- |
-- | It is similar to `Monoid`, except that it applies to types of
-- | kind `* -> *`, like `Array` or `List`, rather than concrete types like
-- | `String` or `Number`.
-- |
-- | `Plus` instances should satisfy the following laws:
-- |
-- | - Left identity: `empty <|> x == x`
-- | - Right identity: `x <|> empty == x`
-- | - Annihilation: `f <$> empty == empty`
class Alt f <= Plus f where
empty :: forall a. f a
-- | The `Alternative` type class has no members of its own; it just specifies
-- | that the type constructor has both `Applicative` and `Plus` instances.
-- |
-- | Types which have `Alternative` instances should also satisfy the following
-- | laws:
-- |
-- | - Distributivity: `(f <|> g) <*> x == (f <*> x) <|> (g <*> x)`
-- | - Annihilation: `empty <*> f = empty`
class (Applicative f, Plus f) <= Alternative f
Snippets from purescript-control
It will be useful to Future/Task
implementations (alt
will be race
).
and with also define Parallel
algebra then in concurrent applicative could implement Alternative
and we would have the race
as well (MonadRace
is removed).
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:25 (20 by maintainers)
Top Results From Across the Web
How to get special characters using Alt key codes or the Word ...
Open a Word file, select Insert > Symbol, scroll down to the new font, choose one of the symbols, and click Insert. Notice...
Read more >The Ultimate List of Helpful Windows Alt Codes to Insert ...
Shortcut Character Unicode Description
Alt + 1 ☺ Smiley Face
Alt + 2 ☻ Dark Smiley Face
Alt + 3 ♥ Heart
Read more >Alt Codes List of Alt Key Codes Symbols
The list of all Alt Codes for special characters and symbols. Learn How to use Alt Key Codes? for special characters and symbols....
Read more >Alt Codes – How to Type Special Characters and Keyboard ...
In Windows, you can type any character you want by holding down the ALT key, typing a sequence of numbers, then releasing the...
Read more >ALT Codes for Special Characters, Signs & Symbols
Character ALT Code Unicode Code Point Character ALT Code Unicode Code Point
␀ ALT 0 U+0000 ␀ ALT 0 U+0000
ALT 1 U+263A ␁ ALT...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@joneshf correct ! (I had a mistake in graph)
here is updated one:
I think that’s asking too much of
Alt
andPlus
. For instance, something likedata Map k v = ...
doesn’t have a sensibleApplicative
instance forMap k
. However, you should be able to write anAlt
instance forMap k
, assumingOrd k
of course. It’s better to haveFunctor
be the superclass ofAlt