문제

If I wanted to add up a list I could do this:

- List.foldr (fn (x, y) => x + y) 0 [1, 2, 3]
val it = 6 : int

Is there any way to write something more along the lines of:

List.foldr + 0 [1, 2, 3]

I tried something like this:

fun inf2f op = fn (x, y) => x op y;
도움이 되었습니까?

해결책

You're close. Add the op keyword in the second example.

- List.foldr op + 0 [1,2,3];
val it = 6 : int
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top