tur/kleisli
stdlib/kleisli.tur
the Kleisli arrow over Option: `Kleisli A B = A -> Option B`.
Since: Phase CA2
defopaque
Kleisli
(Kleisli [A B] :int))
a kind (* -> * -> *) arrow handle; carrier is a fat closure
Since: Phase CA2
defn
k-apply-raw
(k-apply-raw [k : int x : int] :)
internal: invoke a fat closure carrier on x, returning the
defn
kleisli
(kleisli [^fat f] :)
wrap a fat closure `A -> Option B` as a Kleisli arrow.
Parameters
| f | the underlying partial function (returns an int-level Option) |
Returns
A Kleisli A B wrapping f.
Example
(kleisli (fn [x] (if (= x 0) (none) (some (/ 100 x)))))
Since: Phase CA2
defn
k-apply
(k-apply [k : Kleisli x : int] :)
run a Kleisli arrow on an input, returning its int-level Option.
Parameters
| k | the Kleisli arrow | |
| x | the input value |
Returns
The Option result (int carrier): `some y` or `none`.
Example
(some? (k-apply (kleisli (fn [x] (some x))) 7)) ; => true
Since: Phase CA2
definstance
Category[Kleisli]
(definstance Category [Kleisli])
identity is `\a -> some a`; composition runs f, and on
definstance
ArrowZero[Kleisli]
(definstance ArrowZero [Kleisli])
the honest zero arrow over Option: ignore the input