Violation of the left identity law for Future monads in scalaz

前端 未结 2 2087
逝去的感伤
逝去的感伤 2021-02-15 11:01

Suppose I define an instance of the Monad typeclass for Future:

val futureMonad = new Monad[Future] {
  override def point[A](a: ⇒ A):          


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-15 11:57

    Monads such as Try and Future trade one monad law for another law which is more useful in the context they are supposed to be used: An expression composed from (Try or Future), flatMap, map will never throw a non-fatal exception. Call this the "bullet-proof" principle. So actually this approach really protects you against many failures and left-unit law is failed deliberately.

提交回复
热议问题