No matching definitions.

tur/typeclass-monad

stdlib/typeclass-monad.tur

minimal Monad typeclass stub.

Auto-loaded (and loadable directly) so a module can declare (definstance Monad [...] ...) without importing the full typeclass.tur. The full typeclass.tur (with every typeclass) remains available on demand via (load "stdlib/typeclass.tur"); defclass redefinition is idempotent, so the two coexist.

Since: stdlib-hkt-consolidation T1

defclass

Monad

(defclass Monad [^m] [(Applicative m)])

an Applicative whose next step can depend on the previous result.

^mthe computation's type constructor (kind * -> *)
(bind [ma :(m a) k :(fn [a] (m b))] :(m b))

run ma, hand its result to k, and return the computation k builds -- flatMap / >>=. The instance decides what "run" means: Option and Result short-circuit on none / err without calling k. k is a :fn carrier, so a capturing closure works.

(bind (pure x) k)                = (k x)
(bind m pure)                    = m
(bind (bind m k) h)              = (bind m (fn [x] (bind (k x) h)))
(unwrap-or (bind (some 20) (fn [x : int] : (Option int) (some (+ x 1)))) 0)   ; => 21

Superclass: Applicative, so an [^Monad M] body may also pure, ap and fmap. For effects without a monad, see the effects-vs-monads guide.

Since: Phase HKT H3