Documentation

Init.Control.Except

@[inline]
def Except.pure {ε : Type u} {α : Type u_1} (a : α) :
Except ε α

A successful computation in the Except ε monad: a is returned, and no exception is thrown.

Equations
@[inline]
def Except.map {ε : Type u} {α : Type u_1} {β : Type u_2} (f : αβ) :
Except ε αExcept ε β

Transforms a successful result with a function, doing nothing when an exception is thrown.

Examples:

Equations
@[simp]
theorem Except.map_id {ε : Type u} {α : Type u_1} :
@[inline]
def Except.mapError {ε : Type u} {ε' : Type u_1} {α : Type u_2} (f : εε') :
Except ε αExcept ε' α

Transforms exceptions with a function, doing nothing on successful results.

Examples:

Equations
@[inline]
def Except.bind {ε : Type u} {α : Type u_1} {β : Type u_2} (ma : Except ε α) (f : αExcept ε β) :
Except ε β

Sequences two operations that may throw exceptions, allowing the second to depend on the value returned by the first.

If the first operation throws an exception, then it is the result of the computation. If the first succeeds but the second throws an exception, then that exception is the result. If both succeed, then the result is the result of the second computation.

This is the implementation of the >>= operator for Except ε.

Equations
@[inline]
def Except.toBool {ε : Type u} {α : Type u_1} :
Except ε αBool

Returns true if the value is Except.ok, false otherwise.

Equations
@[reducible, inline]
abbrev Except.isOk {ε : Type u} {α : Type u_1} :
Except ε αBool

Returns true if the value is Except.ok, false otherwise.

Equations
@[inline]
def Except.toOption {ε : Type u} {α : Type u_1} :
Except ε αOption α

Returns none if an exception was thrown, or some around the value on success.

Examples:

Equations
@[inline]
def Except.tryCatch {ε : Type u} {α : Type u_1} (ma : Except ε α) (handle : εExcept ε α) :
Except ε α

Handles exceptions thrown in the Except ε monad.

If ma is successful, its result is returned. If it throws an exception, then handle is invoked on the exception's value.

Examples:

Equations
def Except.orElseLazy {ε : Type u} {α : Type u_1} (x : Except ε α) (y : UnitExcept ε α) :
Except ε α

Recovers from exceptions thrown in the Except ε monad. Typically used via the <|> operator.

Except.tryCatch is a related operator that allows the recovery procedure to depend on which exception was thrown.

Equations
@[always_inline]
instance Except.instMonad {ε : Type u} :
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def ExceptT.mk {ε : Type u} {m : Type u → Type v} {α : Type u} (x : m (Except ε α)) :
ExceptT ε m α

Use a monadic action that may return an exception's value as an action in the transformed monad that may throw the corresponding exception.

This is the inverse of ExceptT.run.

Equations
@[inline]
def ExceptT.run {ε : Type u} {m : Type u → Type v} {α : Type u} (x : ExceptT ε m α) :
m (Except ε α)

Use a monadic action that may throw an exception as an action that may return an exception's value.

This is the inverse of ExceptT.mk.

Equations
@[inline]
def ExceptT.pure {ε : Type u} {m : Type u → Type v} [Monad m] {α : Type u} (a : α) :
ExceptT ε m α

Returns the value a without throwing exceptions or having any other effect.

Equations
@[inline]
def ExceptT.bindCont {ε : Type u} {m : Type u → Type v} [Monad m] {α β : Type u} (f : αExceptT ε m β) :
Except ε αm (Except ε β)

Handles exceptions thrown by an action that can have no effects other than throwing exceptions.

Equations
@[inline]
def ExceptT.bind {ε : Type u} {m : Type u → Type v} [Monad m] {α β : Type u} (ma : ExceptT ε m α) (f : αExceptT ε m β) :
ExceptT ε m β

Sequences two actions that may throw exceptions. Typically used via do-notation or the >>= operator.

Equations
@[inline]
def ExceptT.map {ε : Type u} {m : Type u → Type v} [Monad m] {α β : Type u} (f : αβ) (x : ExceptT ε m α) :
ExceptT ε m β

Transforms a successful computation's value using f. Typically used via the <$> operator.

Equations
@[inline]
def ExceptT.lift {ε : Type u} {m : Type u → Type v} [Monad m] {α : Type u} (t : m α) :
ExceptT ε m α

Runs a computation from an underlying monad in the transformed monad with exceptions.

Equations
@[always_inline]
instance ExceptT.instMonadLiftExcept {ε : Type u} {m : Type u → Type v} [Monad m] :
Equations
instance ExceptT.instMonadLift {ε : Type u} {m : Type u → Type v} [Monad m] :
Equations
@[inline]
def ExceptT.tryCatch {ε : Type u} {m : Type u → Type v} [Monad m] {α : Type u} (ma : ExceptT ε m α) (handle : εExceptT ε m α) :
ExceptT ε m α

Handles exceptions produced in the ExceptT ε transformer.

Equations
instance ExceptT.instMonadFunctor {ε : Type u} {m : Type u → Type v} :
Equations
@[always_inline]
instance ExceptT.instMonad {ε : Type u} {m : Type u → Type v} [Monad m] :
Monad (ExceptT ε m)
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def ExceptT.adapt {ε : Type u} {m : Type u → Type v} [Monad m] {ε' α : Type u} (f : εε') :
ExceptT ε m αExceptT ε' m α

Transforms exceptions using the function f.

This is the ExceptT version of Except.mapError.

Equations
@[always_inline]
instance instMonadExceptOfExceptT (m : Type u → Type v) (ε₁ ε₂ : Type u) [MonadExceptOf ε₁ m] :
MonadExceptOf ε₁ (ExceptT ε₂ m)
Equations
  • One or more equations did not get rendered due to their size.
@[always_inline]
instance instMonadExceptOfExceptTOfMonad (m : Type u → Type v) (ε : Type u) [Monad m] :
Equations
instance instInhabitedExceptTOfMonad {m : Type u_1 → Type u_2} {ε α : Type u_1} [Monad m] [Inhabited ε] :
Inhabited (ExceptT ε m α)
Equations
instance instMonadExceptOfExcept (ε : Type u_1) :
Equations
@[inline]
def MonadExcept.orelse' {ε : Type u} {m : Type v → Type w} [MonadExcept ε m] {α : Type v} (t₁ t₂ : m α) (useFirstEx : Bool := true) :
m α

An alternative unconditional error recovery operator that allows callers to specify which exception to throw in cases where both operations throw exceptions.

By default, the first is thrown, because the <|> operator throws the second.

Equations
@[inline]
def observing {ε α : Type u} {m : Type u → Type v} [Monad m] [MonadExcept ε m] (x : m α) :
m (Except ε α)
Equations
def liftExcept {ε : Type u_1} {m : Type u_2 → Type u_3} {α : Type u_2} [MonadExceptOf ε m] [Pure m] :
Except ε αm α
Equations
instance instMonadControlExceptTOfMonad (ε : Type u) (m : Type u → Type v) [Monad m] :
Equations
  • One or more equations did not get rendered due to their size.
class MonadFinally (m : Type u → Type v) :
Type (max (u + 1) v)

Monads that provide the ability to ensure an action happens, regardless of exceptions or other failures.

MonadFinally.tryFinally' is used to desugar try ... finally ... syntax.

  • tryFinally' {α β : Type u} (x : m α) (f : Option αm β) : m (α × β)

    Runs an action, ensuring that some other action always happens afterward.

    More specifically, tryFinally' x f runs x and then the “finally” computation f. If x succeeds with some value a : α, f (some a) is returned. If x fails for m's definition of failure, f none is returned.

    tryFinally' can be thought of as performing the same role as a finally block in an imperative programming language.

Instances
@[inline]
def tryFinally {m : Type u → Type v} {α β : Type u} [MonadFinally m] [Functor m] (x : m α) (finalizer : m β) :
m α

Execute x and then execute finalizer even if x threw an exception

Equations
@[always_inline]
Equations
@[always_inline]
instance ExceptT.finally {m : Type u → Type v} {ε : Type u} [MonadFinally m] [Monad m] :
Equations
  • One or more equations did not get rendered due to their size.