No matching definitions.

tur/typeclass-monaderror

stdlib/typeclass-monaderror.tur

minimal MonadError typeclass stub.

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

Since: stdlib-hkt-consolidation T4

defclass

MonadError

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

a Monad with an error channel you can raise into and recover from.

^mthe computation's type constructor (kind * -> *), e.g. (Result _ B)
(throw-error [err] :int)

a failed computation carrying err -- an err for Result.

(catch-error [ma handler :fn] :int)

ma unchanged if it succeeded; otherwise the computation handler builds from the error. handler is a :fn carrier, so a capturing closure works.

(catch-error (throw-error e) h)    = (h e)
(catch-error (pure x) h)           = (pure x)
(ok-val (:: (catch-error (:: (err 5) (Result int int)) (fn [e : int] : (Result int int) (ok (* e -1)))) (Result int int)))   ; => -5

Both methods return the :int carrier, so ascribe the result to read it: (:: (catch-error ma h) (Result int int)).

Superclass: Monad.

(Result _ B)

Since: stdlib-hkt-consolidation T4