Is it better to define Functor in terms of Applicative in terms of Monad, or vice versa?

前端 未结 5 475
南笙
南笙 2021-02-02 13:25

This is a general question, not tied to any one piece of code.

Say you have a type T a that can be given an instance of Monad. Since every mona

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 14:18

    The magic here, that the Haskell uses the Kleisli-tiplet notation of a monad, that is more convenient way, if somebody wants to use monads in imperative programming like tools.

    I asked the same question, and the answer come after a while, if you see the definitions of the Functor, Applicative, Monad in haskell you miss one link, which is the original definition of the monad, which contains only the join operation, that can be found on the HaskellWiki.

    With this point of view you will see how haskell monads are built up functor, applicative functors, monads and Kliesli triplet.

    A rough explanation can be found here: https://github.com/andorp/pearls/blob/master/Monad.hs And other with the same ideas here: http://people.inf.elte.hu/pgj/haskell2/jegyzet/08/Monad.hs

提交回复
热议问题