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
("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.