Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ここに実装があります:
def reverse[A](l: List[A]): List[A] = foldLeft(l, List[A]())((acc,h) => Cons(h,acc))
(acc,h); を使用してコンパイラが何を解釈するのかわかりません。最初に、f 関数は 2 つのリストである (ListA,l) を満たすので、Cons は 2 つのリストでも機能しますか?
ありがとう
Consに渡された関数と同じように、1 つのリストと 1 つの要素でfoldLeft動作します。
Cons
foldLeft
foldLeftonの宣言List[A]は次のとおりです。
List[A]
def foldLeft[B](z: B)(f: (B, A) ⇒ B): B
したがって、impl を次のように記述できます。
l.foldLeft(List[A]())((acc, h) => ...)
Bそして、型がであることがわかるList[A]ので、私たちへの 2 つの引数fはacc(型のList[A]) とh(型のA) です。
B
f
acc
h
A