Suppose I define an instance of the Monad class for Future :
val futureMonad = new Monad[Future] { override def point[A](a: β A): Future[A] = Future(a) override def bind[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = fa flatMap f }
Strictly speaking, this is not a monad, since it violates the law of left identity:
futureMonad.point(a) bind f == f(a)
If f throws an exception, the result of the expression on the left side will be unsuccessful Future , while the right side, of course, will throw an exception.
But what are the practical consequences of this violation? How can a system fail as a result of this "misbehavior"?
scala monads typeclass
Otavio macedo
source share