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
Type Casting

The infix operator "~" (spoken as "tilde" or "twiddle") is used for assigning a new type to an expression - that is for "type casting".

 <E>~<T>
 

represents casting the value of the expression E to type T. Whatever the type of E, the type of E~T is T. By including the type cast, the programmer is effectively making the assertion that E will actually belong to T at the the time the cast is executed. However, the Fabl implementation does not verify this, except in the case of casting to or from a Literal, int, double,string, or boolean. Except in the case of these datatypes, the type cast does not entail any run-time computation.

Here's an example:

var Resource a;
var a = 3 ~ Resource;
a~int + 1;
-->4

A frequent use of the cast operation is to convert between Literal and the datatypes int, double, string, and boolean. Casting attempts to interpret a literal in the correct fashion according to the destination of the cast. For example

("2.3"~Literal~double)+1;
-->3.3

boolean hasType(Resource x,Class tp)

determines whether x belongs to type tp according to the information available. The specifics are as follows.

For each resource x, Fabl maintains an explicit list of types to which x belongs as the value of its rdf:type property. This explicit list includes only maximally specific classes under the rdfs:subClassOf relation. That is, if tp1 is a subclass of tp2, and tp1 is present in x.rdf:type, then tp2 will not appear in x.rdf:type, since membership of x in tp2 is implied by membership in tp1. hasType also makes use of this simple kind of type deduction. hasType(x,tp) returns true if tp is known to be a subclass of one of the types specified explicitly among the values of x.rdf:type.