Documentation

Hale.Base.Control.Monad

def Control.Monad.join {α : Type} {m : TypeType} [Monad m] (mma : m (m α)) :
m α

Monadic join: flattens a nested monadic value.

$$\text{join} : m\,(m\;\alpha) \to m\;\alpha$$ $$\text{join}\;mma = mma \mathbin{>>=} \text{id}$$

Equations
Instances For
    def Control.Monad.void {α : Type} {f : TypeType} [Functor f] (fa : f α) :

    Discard the result of a functor action, keeping only the effect.

    $$\text{void} : f\;\alpha \to f\;\text{Unit}$$ $$\text{void}\;fa = (\lambda\;\_ \Rightarrow ()) \mathbin{<\$>} fa$$

    Equations
    Instances For
      def Control.Monad.when {m : TypeType} [Monad m] (b : Bool) (action : m Unit) :

      Conditional execution: run the action only when the boolean is true.

      $$\text{«when»}\;b\;a = \begin{cases} a & \text{if } b \\ \text{pure}\;() & \text{otherwise} \end{cases}$$

      Equations
      Instances For
        def Control.Monad.unless {m : TypeType} [Monad m] (b : Bool) (action : m Unit) :

        Conditional execution: run the action only when the boolean is false.

        $$\text{unless}\;b\;a = \text{when}\;(\lnot b)\;a$$

        Equations
        Instances For
          def Control.Monad.mapM_ {α : Type u_1} {β : Type} {m : TypeType} [Monad m] (f : αm β) :
          List αm Unit

          Map a monadic function over a list, discarding the results.

          $$\text{mapM\_}\;f\;[x_1, \ldots, x_n] = f\;x_1 \mathbin{>>} \cdots \mathbin{>>} f\;x_n \mathbin{>>} \text{pure}\;()$$

          Equations
          Instances For
            def Control.Monad.forM_ {α : Type u_1} {β : Type} {m : TypeType} [Monad m] (xs : List α) (f : αm β) :

            Flipped mapM_: iterate over a list with a monadic action, discarding results.

            $$\text{forM\_}\;xs\;f = \text{mapM\_}\;f\;xs$$

            Equations
            Instances For
              def Control.Monad.foldM {β : Type} {α : Type u_1} {m : TypeType} [Monad m] (f : βαm β) (init : β) :
              List αm β

              Monadic left fold over a list.

              $$\text{foldM}\;f\;z\;[x_1, \ldots, x_n] = f\;z\;x_1 \mathbin{>>=} \lambda z_1 \Rightarrow f\;z_1\;x_2 \mathbin{>>=} \cdots$$

              Equations
              Instances For
                def Control.Monad.filterM {α : Type} {m : TypeType} [Monad m] (p : αm Bool) :
                List αm (List α)

                Monadic filter: keep elements for which the predicate returns true in the monad.

                $$\text{filterM}\;p\;xs = [x \in xs \mid p\;x]$$

                Equations
                Instances For
                  def Control.Monad.zipWithM {α : Type u_1} {β : Type u_2} {γ : Type} {m : TypeType} [Monad m] (f : αβm γ) :
                  List αList βm (List γ)

                  Monadic zip: apply a binary monadic function to corresponding elements.

                  $$\text{zipWithM}\;f\;[a_1, \ldots]\;[b_1, \ldots] = [f\;a_1\;b_1, f\;a_2\;b_2, \ldots]$$

                  Equations
                  Instances For
                    def Control.Monad.replicateM {α : Type} {m : TypeType} [Monad m] (n : Nat) (ma : m α) :
                    m (List α)

                    Repeat a monadic action n times, collecting the results.

                    $$\text{replicateM}\;n\;ma = [ma, ma, \ldots]\text{ (n times)}$$

                    Equations
                    Instances For
                      def Control.Monad.replicateM_ {α : Type} {m : TypeType} [Monad m] (n : Nat) (ma : m α) :

                      Repeat a monadic action n times, discarding the results.

                      $$\text{replicateM\_}\;n\;ma = ma \mathbin{>>} \cdots \mathbin{>>} ma \mathbin{>>} \text{pure}\;()$$

                      Equations
                      Instances For
                        def Control.Monad.fish {α : Sort u_1} {β γ : Type} {m : TypeType} [Monad m] (f : αm β) (g : βm γ) :
                        αm γ

                        Kleisli composition (left-to-right): $(f \mathbin{>=>} g)\;a = f\;a \mathbin{>>=} g$.

                        $$\text{fish} : (\alpha \to m\;\beta) \to (\beta \to m\;\gamma) \to \alpha \to m\;\gamma$$

                        Equations
                        Instances For
                          def Control.Monad.fishBack {β γ : Type} {α : Sort u_1} {m : TypeType} [Monad m] (g : βm γ) (f : αm β) :
                          αm γ

                          Kleisli composition (right-to-left): $(g \mathbin{<=<} f) = f \mathbin{>=>} g$.

                          $$\text{fishBack} : (\beta \to m\;\gamma) \to (\alpha \to m\;\beta) \to \alpha \to m\;\gamma$$

                          Equations
                          Instances For
                            theorem Control.Monad.join_pure {α : Type} {m : TypeType} [Monad m] [LawfulMonad m] (x : m α) :
                            join (pure x) = x

                            Join-pure law: joining a pure value is the identity.

                            $$\text{join}\;(\text{pure}\;x) = x$$