tur/typeclass-applicative
minimal Applicative typeclass stub.
Loaded by schema.tur (and loadable directly) so a module can declare (definstance Applicative [...] ...) 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
Applicative
(defclass Applicative [^f] [(Functor f)])
a Functor that can lift a plain value and apply a wrapped function.
| ^f | the container's type constructor (kind * -> *) |
(pure [x :a] :(f a))-
xin the minimal context --somefor Option,okfor Result. Dispatches on its return type, so the expected type has to be known:(:: (pure 5) (Option int)). (ap [ff :(f (fn [a] b)) fa :(f a)] :(f b))-
apply the function inside
ffto the value insidefa. The contexts combine the way the instance says -- for Option, a none on either side gives none.
(ap (pure (fn [x] x)) v) = v (ap (pure f) (pure x)) = (pure (f x)) (fmap v f) = (ap (pure f) v)
(unwrap-or (ap (some (fn [x : int] : int (* x 2))) (some 21)) 0) ; => 42
Superclass: Functor, so an [^Applicative F] body may also fmap.
Since: Phase HKT H3