What advantage does Monad give us over an Applicative?

后端 未结 8 582
心在旅途
心在旅途 2020-12-02 11:16

I\'ve read this article, but didn\'t understand last section.

The author says that Monad gives us context sensitivity, but it\'s possible to achieve the same result

8条回答
  •  离开以前
    2020-12-02 12:04

    Now that ApplicativeDo extension become pretty common thing, the difference between Monad and Applicative can be illustrated using simple code snippet.

    With Monad you can do

    do
       r1 <- act1
       if r1
            then act2
            else act3
    

    but having only Applicative do-block, you can't use if on things you've pulled out with <-.

提交回复
热议问题