Wafl Home

Program Structure Tutorial

Lambda Functions

Lambda functions are one of the most used formalizations of algorithms. However, in functional programming languages, term lambda function is often related to different concepts of unnamed function definitions. Because functions are first order citizens, very often used as applications arguments, it is very helpful if language allows specifying a function inline, i.e. at the place of its usage, instead an explicit function definition.

Programming language Wafl supports lambda functions in the following form:

\<arg1>,...,<argn>: <exp>

In the following example lambda functions are used to write simple functions without theirs explicit named definitions. In combine we use lambda functions instead of more complex solution with named function:

combine( f, g ) = combine1( f, g, _ )
	where { combine1(f,g,x) = f(g(x)); }

In repeat we use lambda functions to write identity function. In all applications, lambda functions are used instead of inc function.

Source code:

{#
(\x:x+1)(0),
combine(\x:x+1,\x:x+1)(0),
repeat(\x:x+1,10)(0)   
#}
where{
    combine( f, g ) = ( \f,g,x : f(g(x)) )( f, g, _ );
    repeat( f, n ) =
        if n=0 
            then \x:x 
            else combine( f, repeat(f,n-1) );
}

Result:

{# 1, 2, 10 #}

 

Table of Contents

Let's Start

Program Structure

Primitive Data Types

List

Tuple

Record

HTML

Command Line Interpreter

Using Web Servers

Syntax

Examples

Tips

The most of examples evaluates with both command line and Web server Wafl interpreters. If any example is based on specific features of an interpreter, it is explicitly annotated.