tur/typeclass-alternative
stdlib/typeclass-alternative.tur
minimal Alternative typeclass stub.
Loaded by schema.tur (and loadable directly) so a module can declare (definstance Alternative [...] ...) without importing the full typeclass.tur. The full typeclass.tur (with every typeclass) is still available on demand via (load "stdlib/typeclass.tur").
Since: Phase SC7
defclass
Alternative
(defclass Alternative [^f] [(Applicative f)])
an Applicative with a failure value and a first-success choice.
Type parameters
| ^f | the container's type constructor (kind * -> *) |
Methods
(empty [a] :(f a))-
the failing/empty value -- none for Option.
aonly picks the instance; it is not read. (alt-or [x :(f a) y :(f a)] :(f a))-
xif it succeeded, elsey-- the first some, the first parse that matched.
Laws
(alt-or (empty w) x) = x (alt-or x (empty w)) = x (alt-or (alt-or x y) z) = (alt-or x (alt-or y z))
Example
(unwrap-or (alt-or (none) (some 7)) 0) ; => 7
Superclass: Applicative.
Since: Phase HKT H7