The Fabl Manual
Function Index
Class Index
Globals Index
Libraries
Contents

Title Page
Introduction
Sample Code
Architecture
Syntax
Strong Typing
Polymorphism
Operators
Help
Errors
Configuration
RDF
Namespaces
Owl
Datatypes
Resources
Dot ops
Coercion
Type Casting
nil

Types
string
id
int
double
boolean
Literal
Containers
Functions
void

Home
Regarding
The Path
Classes
Delegation
Functional Values
Read/Write
Load/Store
Libraries
Imports
CGI
Polymorphism

Fabl is polymorphic, in the sense that distinct functions may be given the same name as long as their arguments' types differ. The functions below define two variants of twice, one taking integers, and one strings.

int function twice(int x)
{
return 2*x;
}


string function twice(string s)
{
return s+s;
}

(+ is concatenation for strings. See the section on strings for details.) Then,

twice(2);
->4
twice("hello");
->hellohello
In this manual, functions will be introduced in the form:

int function twice(int x)

that is, by the first lines of their definitions.

Fabl also supports parametric polymorphism, meaning that the types of the inputs and output of a function take on an infinite set of possible values, usually parameterized by the base types of constructed types such as sequences. Here is an example:

For each type <tp>, SeqOf(<tp>) is the type of sequences whose elements are of type <tp> (see the section on sequences for details). The function:

SeqOf(<tp>) function plus(SeqOf(<tp>) x,SeqOf(<tp>) y)

concatenates the sequences x and y. Its output type is the same as the types of its inputs. For example, in

var a = plus([2,3],[4,5]);

the type of a is SeqOf(int), while in

var b = plus(["a","b"],["c","d"]);
the type of b is SeqOf(string).

As in the above example, symbols that are intended to vary over types rather than denote a particular type are enclosed in angle brackets (<>).

Fabl programmers can introduce their own parametrically polymorphic functions, but this facility is not yet documented. A future document - the Fabl Meta Manual - will cover metaprogramming in Fabl (that is, programming whose purpose is to manipulate programs); parametric polymorphism is a part of the metaprogramming facility. Fabl itself is almost entirely implemented using its own metaprogramming constructs.