Int -> Int): Int -> Int = x -> f(f(x)) We can use the function twice as follows: twice(x -> x + 1)(0) Here the call to twice(x -> x + 1) returns a function that will increment its argument two times. Thus the result of the whole expression is 0 + 1 + 1 = 2. Parametric polymorphism The following program fragment illustrates a polymorphic function that maps a function f: a -> b over a list of elements of type a returning a list of elements of type b: def map(f: a -> b, l: List[a]): List[b] = match l { case Nil => Nil case x :: xs => f(x) :: map(f, xs) } The map function recursively traverses the list l and applies f to each element constructing a new list. Flix supports type parameter elision hence it is not required that the type parameters a and b are explicitly introduced. Extensible records The following program fragment shows how to construct a record with two fields x and y: def point2d(): {x: Int, y: Int} = {x = 1, y = 2} Flix uses row polymorphism to type records. The sum function below takes a record that has x and y fields (and possibly other fields) and returns the sum of the two fields: def sum(r: {x: Int, y: Int | rest}): Int = r.x + r.y The following are all valid calls to the sum function: sum({x = 1, y = 2}) sum({y = 2, x = 1}) sum({x = 1, y = 2, z = 3}) Notable features Polymorphic effects The Flix type and effect system separates pure and impure expressions. A pure expression is guaranteed to be referentially transparent. A pure function always returns the same value when given the same argument(s) and cannot have any (observable) side-effects. For example, the following expression is of type Int and is Pure: 1 + 2 : Int & Pure whereas the following expression is Impure: Console.printLine("Hello World") : Unit & Impure A higher-order function can specify that a function argument must be pure, impure, or that it is effect polymorphic. For example, the definition of Set.exists requires that its function argument f is pure: // The syntax a -> Bool is short-hand for a -> Bool & Pure def exists(f: a -> Bool, xs: Set[a]): Bool = ... The requirement that f must be pure