Why `Concurrently` is not a monad in Haskell?

故事扮演 提交于 2019-12-10 17:09:54

问题


I'm reading the doc of package async, and trying to find something similar to JavaScript's Promise, and I find Concurrently, which is the most close concept that implemented Functor, Applicative (Promise.all), Alternative (Promise.race). But it doesn't implement Monad (Promise.then), I'm wondering why.

I think it maybe because (>>=) is a sequential operation, which conflict with the name Concurrently, but is this the only reason? is there some more important reason here?


回答1:


The Monad typeclass states that (<*>) and ap should be equivalent. (<*>) for Concurrently evaluates both the LHS and the RHS at the same time. ap can't evaluate the RHS until the LHS is done, since (>>=) needs to finish evaluating the LHS before it can call the function that gives it the RHS.



来源:https://stackoverflow.com/questions/56032669/why-concurrently-is-not-a-monad-in-haskell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!