Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I fold with an infix operator without writing out an anonymous function?

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;
like image 241
AJcodez Avatar asked Feb 15 '13 07:02

AJcodez


1 Answers

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

- List.foldr op + 0 [1,2,3];
val it = 6 : int
like image 140
Brian Avatar answered Sep 30 '22 04:09

Brian