_必须遵循[Curried]方法

时间:2014-01-07 02:22:23

标签: scala

我正在map3 // Exercise 3: The apply method is useful for implementing map3, map4, and so on // and the pattern is straightforward. Implement map3 and map4 using only // unit, apply, and the curried available on functions. def map3[A,B,C,D](fa: F[A], fb: F[B], fc: F[C])(f: (A, B, C) => D): F[D] = { def foo: (A => B => C => D) = (f _).curried // compile-time error def fooF: F[A => B => C => D] = unit(foo) val x: F[B => C => D] = apply(fooF)(fa) val y: F[C => D] = apply(x)(fb) val z: F[D] = apply(y)(fc) z } 处理[error] C:\...\Applicative.scala: _ must follow method; cannot follow f.type [error] def foo: (A => B => C => D) = (f _).curried [error] ^

curried

上面提到的一行发生了一(1)次编译时错误:

{{1}}

我通过这篇文章成功获得了{{1}}版本的功能 - Functional Programming in Scala

但是,我不明白上面的编译时错误。

1 个答案:

答案 0 :(得分:6)

错误是因为f这里是一个函数,而不是一个方法; f _语法是将方法转换为函数,这在此不是必需的。只需写下def foo: A => B => C => D = f.curried