Documentation

Hale.Base.Control.Exception

def Control.Exception.try' {α : Type} (action : IO α) :

Try an action, catching IO errors into Either String α.

$$\text{try'} : \text{IO}\ \alpha \to \text{IO}\ (\text{Either}\ \text{String}\ \alpha)$$

On success, returns Right a. On failure, returns Left (toString e).

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    def Control.Exception.catch' {α : Type} (action : IO α) (handler : StringIO α) :
    IO α

    Catch an IO error with a handler.

    $$\text{catch'} : \text{IO}\ \alpha \to (\text{String} \to \text{IO}\ \alpha) \to \text{IO}\ \alpha$$

    If action succeeds, returns its result. If it throws, the stringified error is passed to handler.

    Equations
    Instances For
      def Control.Exception.bracket {α β : Type} (acquire : IO α) (release : αIO Unit) (use : αIO β) :
      IO β

      Bracket pattern: acquire a resource, use it, and release it.

      $$\text{bracket} : \text{IO}\ \alpha \to (\alpha \to \text{IO}\ \text{Unit}) \to (\alpha \to \text{IO}\ \beta) \to \text{IO}\ \beta$$

      Resource safety: release is always called, whether use succeeds or throws. If use throws, the original error is re-thrown after release completes.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def Control.Exception.finally' {α : Type} (action : IO α) (cleanup : IO Unit) :
        IO α

        Ensure cleanup runs whether the action succeeds or fails.

        $$\text{finally'} : \text{IO}\ \alpha \to \text{IO}\ \text{Unit} \to \text{IO}\ \alpha$$

        Equivalent to bracket (pure ()) (fun _ => cleanup) (fun _ => action). Named finally' to avoid conflict with Lean's finally keyword.

        Equations
        Instances For
          def Control.Exception.onException {α : Type} (action : IO α) (cleanup : IO Unit) :
          IO α

          Run cleanup only if the action throws.

          $$\text{onException} : \text{IO}\ \alpha \to \text{IO}\ \text{Unit} \to \text{IO}\ \alpha$$

          On success, cleanup is skipped. On failure, cleanup runs then the original error is re-thrown.

          Equations
          Instances For
            @[inline]
            def Control.Exception.evaluate {α : Type} (a : α) :
            IO α

            Evaluate a pure value in IO, forcing any thunks.

            $$\text{evaluate} : \alpha \to \text{IO}\ \alpha$$

            In Lean (strict evaluation), this is simply pure. Provided for Haskell API compatibility.

            Equations
            Instances For