Next: Equality, ordering, and hashing
Up: Basic data types and
Previous: Basic data types and
Index
In general.diesel:
The following types, classes, and/or objects are special, and
predefined:
void is the type of methods that do not return a ``real''
result. void is implicitly a supertype of all other types. The
void object can be returned explicitly from a method, if
necessary.
predefined object void;
any is implicitly the supertype of all other non-void
types. It can be used as the argument type of functions that work
over any (non-void) object.
predefined abstract class any;
The none type is the result type of functions that never return
to their callers, and the type of closure arguments that are never
invoked. none is a subtype of all other types, and there is no
object of this type.
predefined type none;
The dynamic type disables static type checking. It's used to
explicitly declare the type of a variable that cannot be statically
checked. A value of any type can be assigned to a variable of type
dynamic, and vice versa. (The Diesel compiler will perform run-time
typechecking to ensure type safety even in the face of uses of dynamic
or of static type errors.)
predefined type dynamic;
All objects can be compared for identity. Two things that print
out the same may not be ==, e.g. "abc" == "abc" may return
false. By default, operations on collections that compare
elements, such as finding an element in a list or adding an
element to a set, use = (implemented by comparable objects)
rather than ==, unless the collection's name includes
identity_
.
fun ==(l:any, r:any):bool; - object identity test (use = instead for value equality testing)
fun !==(l:any, r:any):bool; - not ==
Any object can be converted to a string, although the default
version can be low-level and ugly. Most commonly-used objects
override print_string
to return something prettier.
(A two-element version of print permits strings to be printed to
files.)
fun print_string(x:any):string; - return a string print version
fun print(x:any):void; - print the print_string
fun print_line(x:any):void; - print the print_string and a newline
fun print_line():void; - just print a newline
The error method is the standard way to prematurely quit
execution of a Diesel program.
fun error(msg:ordered_collection[`T]):none; - quits with an error message; does not return
upcast[T] changes the static type of its argument to T from a
fun upcast[T](x:`S <= T):T;
Next: Equality, ordering, and hashing
Up: Basic data types and
Previous: Basic data types and
Index
Cecil/Vortex Project