我希望能够在我自己的应用函子上使用scalaz的|@|
示例:val spread: Source[Yield] = (y2 |@| y1)(_ - _)
这是我的课
sealed abstract class Source[+A] {
def map[B](f: A => B): Source[B]
def unit[A](a: A): Source[A]
def pureList[A](la: List[A]): Source[A]
def zero[A]: Source[A]
def map2[A, B, C](as: Source[A], bs: Source[B], f: (A, B) => C): Source[C]
}
我确定我必须实现map
因为它是一个函子。
应用程序可以通过多种方式实现:例如使用apply()
和unit()
或map2()
和unit()
。
我也需要ap
和pure
吗?
如您所见,我不确定需要什么。
implicit val mya = new Applicative[Source] {}
让编译器为您回答这个问题:
object creation impossible, since:
it has 2 unimplemented members.
/** As seen from <$anon: scalaz.Applicative[Source]>, the missing signatures are as follows.
* For convenience, these are usable as stub implementations.
*/
// Members declared in scalaz.Applicative
def point[A](a: => A): Source[A] = ???
// Members declared in scalaz.Apply
def ap[A, B](fa: => Source[A])(f: => Source[A => B]): Source[B] = ???