trait Comonad[M[_]] {
// map
def >>[A,B](a: M[A])(f: A => B): M[B]
// extract | coeta
def counit[A](a:M[A]): A
// coflatten | comu
def cojoin[A](a: M[A]): M[M[A]]
}
object Comonad {
implicit def listComonad[A]: Comonad[List]
=
new Comonad[List] {
def counit[A](lsa: List[A])
=
lsa match { case List(a) => a }
def cojoin[A](lsa:List[A]): List[List[A]]
=
List(lsa)
def >>[A,B](lsa: List[A])(f: A => B): List[B]
=
lsa map f
}
}所以是的,我在看这个,我没有那种正确的感觉.
有人介意纠正这个问题,或者提供一两个其他简单的共餐吗?
https://codereview.stackexchange.com/questions/27685
复制相似问题