What monads can be expressed as Free over some functor?

后端 未结 4 1597
孤街浪徒
孤街浪徒 2020-12-08 01:01

The documentation for Free says:

A number of common monads arise as free monads,

  • Given data Empty a, Free Empty
4条回答
  •  遥遥无期
    2020-12-08 02:01

    All monads can be expressed as the Free Monad. Their additional properties (like MonadFix and Cont) could be stripped off that way because the Free Monad is not a Free MonadFix or Free Cont.

    The general way is to define Functor's fmap in terms of liftM and then wrap Free around that Functor. The resulting Monad can be reduced to the previous/actual Monad by specifying how the functions return and join (Pure and Impure) have to be mapped to the actual Monad.

提交回复
热议问题