0
내가 Functional Programming in 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
}
하나 (1) 컴파일시 에러가 위의 언급 한 줄에 발생합니다
[error] C:\...\Applicative.scala: _ must follow method; cannot follow f.type
[error] def foo: (A => B => C => D) = (f _).curried
[error]
^
I을 이 게시물을 통해 curried
버전의 기능을 성공적으로 가져올 수있었습니다 (Using FunctionX#curried).
그러나 위의 컴파일 타임 오류를 이해하지 못합니다.
감사합니다. 작동했습니다 (아직 수락 할 수 없음). @Huw. 'f'가 메소드 일 때'f'가하는 것은 무엇입니까? –
그것은 해당 기능으로 바뀝니다. 스펙의 §6.7을보십시오. 또한 썽크를 무의미한 함수로 바꿀 것입니다 :'def foo [A] (v : => A) :() => A = v'' – Hugh
. 제쳐두고, 여러분 (또는 그 밖의 사람들)은 제 map3 구현에 대해 의견이 있습니까? 비평은 높이 평가했다. –