No matching definitions.

tur/typeclass-applicative

stdlib/typeclass-applicative.tur

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

defclass

Applicative

(defclass Applicative [^f] [(Functor f)])

a Functor that can lift a plain value and apply a wrapped function.

^fthe container's type constructor (kind * -> *)
(pure [x :a] :(f a))

x in the minimal context -- some for Option, ok for 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 ff to the value inside fa. 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