tur/typeclass-monad
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
Monad
(defclass Monad [^m] [(Applicative m)])
an Applicative whose next step can depend on the previous result.
| ^m | the computation's type constructor (kind * -> *) |
(bind [ma :(m a) k :(fn [a] (m b))] :(m b))-
run
ma, hand its result tok, and return the computationkbuilds -- flatMap />>=. The instance decides what "run" means: Option and Result short-circuit on none / err without callingk.kis a:fncarrier, 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