PS

Free monad

Initial algebraの族からのadjunction

  • category:  \mathcal{S} : \text{has binary coproducts}
  • endofunctor:  F : \mathcal{S} \rightarrow \mathcal{S}
  • forgetful functor:  U : F \unicode{x2012} \mathcal{Alg} \rightarrow \mathcal{S}

について、initial algebraの族:

  •  \big( \langle \mathtt{pure}_ a, \mathtt{free} _ a \rangle : a + F(\mathtt{Free} _ a) \rightarrow \mathtt{Free} _ a \big) _ {a \in \mathcal{S} }

が存在するならば、Initial algebras with parameters - PSより、これをnaturalにするfunctor:

  •  \mathtt{Free}(a) = \mathtt{Free} _ a

を作ることが出来る。いま、

  •  L : \mathcal{S} \to  F \unicode{x2012} \mathcal{Alg}
  •  L(a) := (\mathtt{Free}(a), \mathtt{free} _ a)

とすると

  •  \big( \mathtt{pure} _ a : a \to U(L(a)) \big)  _ {a \in \mathcal{S} }

は、initial morphismの族となるので

  •  L \dashv U

逆に、unit-adjunction:

  •  \big( \mathtt{pure} _ a : a \rightarrow U(L(a)) \big) _ {a \in \mathcal{S} }

が存在すれば、

  •  \big( \langle \mathtt{pure} _ a, L(a) \rangle \big ) _ { a \in \mathcal{S} }

は、initial algebraの族となる。

Free monad

Adjunctionからのmonad - PSにより、

  •  T(a) := U(L(a)) = \mathtt{Free}(a)

は、monadになる。*1

Haskellにて

Control.Monad.Freeより、

data Free f a = Pure a | Free (f (Free f a))

Initial algebraからのcatamorphism*2は、

cata :: Functor f => (a -> b) -> (f b -> b) -> Free f a -> b
cata h phi (Pure a) = h a
cata h phi (Free m) = phi (fmap (cata h phi) m)

で、これから全て導かれる(はず)。

Adjunctionのunitは、constructorPureで、counitはiterになる(と思う)。

参考文献

*1:Free monadの数学的定義はややこしい模様: Category of monads - PS

*2:mediatorのこと