//"Currying" an arbitrary Int->Int->Int function
//Logging the number of calls to an Int->Int->Int function by embedding it in a closure

function (int)->int bindInt((int,int)->int f, int first) {
    function int return(int second) f(first,second);
    return
};

function int add(int a, int b) a+b;

var (int)->int add5;
add5 := bindInt(add, 5);

print(add5(3));


var ()->int getCalls;

function (int,int)->int logCalls((int,int)->int f) {
    var int calls;
    calls := 0;
    function int getCalls2() calls;
    getCalls := getCalls2;
    function int return(int first, int second) {
        calls := calls + 1;
        f(first,second)
    };
    return
};

var add add_;
add_ := logCalls(add);

print(add_(1,6), add_(10,5));
print(getCalls());
