我是scala编程的新手,有没有人能解释这一点,为什么这个想法显示了这些错误,但效果很好?
case class FlatMap[A, B](sub: IO[A], f: A => IO[B]) extends IO[B]
@annotation.tailrec
def run[A](io: IO[A]): A = io match {
case Pure(a) => a
case Suspend(r) => r()
case FlatMap(sub, k) => sub match {
case Pure(a) => run(k(a `Type mismatch, Required Nothing, Found Any`))
case Suspend(r) => run(k(r() `same as above`))
case FlatMap(y, g) => run(y flatMap (a => g(a `same as above`) flatMap k `Required Any => IO[NotInferredB], Found: Nothing => IO[A]`))
}
}
我想了解更多关于函数式编程和scala中的单子,
有什么好的资源吗?谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!