创建自定义Applicative Functor以与scalaz | @ |一起使用需要哪些方法

Adr*_*ian 4 functional-programming scala scalaz applicative

我希望能够使用scalaz的| @ | 在我自己的applicative functor上.

例:
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]
}
Run Code Online (Sandbox Code Playgroud)

我确定我必须实施,map因为它是一个仿函数.
一个适用可以通过多种方式来实现:例如使用apply()unit()map2()unit().

我需要appure呢?

如你所见,我不确定需要什么.

Oli*_*ain 6

implicit val mya = new Applicative[Source] {}
Run Code Online (Sandbox Code Playgroud)

让编译器为您回答这个问题:

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] = ???
Run Code Online (Sandbox Code Playgroud)