3 ms·
In your notation it would be something like final case class Mon[A](v: A, m: M) { def flatMap[B](f: A => Mon[B]): Mon[B] = Mon(f(this.v).v, f(this.
by edflsafoiewq 7y ago
In your notation it would be something like
final case class Mon[A](v: A, m: M) {
def flatMap[B](f: A => Mon[B]): Mon[B] =
Mon(f(this.v).v, f(this.v).m * this.m) // * is M's binary operation
}
object Mon {
def pure(v: A): Mon[A] =
Mon(v, M.unit) // M.unit is M's identity element
}