func.eh

Functional transformations. More...

use "func.eh"

Functions

def Function.curry(arg: Any): Function;

Description

This header defines functional transformations.

Partial function application

The curry function returns function with the first argument already applied. The type transformation is the following:
 (type1,type2,...,typeN):rettype    =>    (type2,...,typeN):rettype
 (type1,type2,...,typeN)            =>    (type2,...,typeN)
For example:
use "io"

def sum(a: Int, b: Int): Int = a + b

def main(args: [String]) {
  // the next function will be (Int):Int
  // and it will act as adding 3 to the argument
  var plus3 = sum.curry(3)
  println( plus3(2) )  // => 5
  // the function sum.curry itself is a "curried" function,
  // i.e. it is a chain of functions (Int):(Int):Int
  var chainsum = sum.curry
  println( chainsum(1)(8) )  // => 9
}

Function details

def Function.curry(arg: Any): Function;
Applies first argument to the function returning function with less arguments. The function being transformed must accept at least one argument. Actual returning type is calculated from the function being curried.