Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Untupling a function

Suppose I want to run a fold using a function that expects a tuple, f (x, y). This can be done with

List.fold (fun x y -> f (x, y)) x xs

I kind of feel there ought to be a higher-order function that abstracts out that pattern, takes a function that expects a tuple and turns it into a function that expects two separate arguments.

Is there such a function in the F# standard library? If not, easy enough to write but what should it idiomatically be called? untuple?

like image 734
rwallace Avatar asked Mar 24 '17 08:03

rwallace


1 Answers

That function is normally called curry in most functional languages. It's definition is:

let curry f x y = f (x, y)

Unfortunately it's not in the F# core lib, but it's available in many external base libraries, like F#x and F#+.

like image 125
Gus Avatar answered Oct 21 '22 23:10

Gus