Camelot has a built-in polymorphic list type α list . The empty list (which is represented by the null value) is denoted by [] and the cons operation is denoted by ::. For example, to define the list length function (which is not presently built in) one can write
let length l = match l with [] => 0 | h::t => 1+length t |
Literal lists can also be represented by the syntax used in SML. For example
let n = let l = [1,5,7,9,33] in length l |
This syntax is not allowed in match statements.
Camelot has various built-in infix operators.
arithmetic operations on integers
arithmetic operations on floating-point values
numeric comparisons.
Note that the equality operator = can also be applied to strings and other objects. However, it is interpreted as equality of references and hence will usually fail to give the correct result; for strings, one should use the function same_string.
boolean operators.
The last two of these only evaluate as many expressions as are required to decide the result; for example, if we attempt to evaluate the expression e1 andalso e2 then e2 will not be evaluated if e1 evaluates to true.
string concatenation.
There are also several built-in functions. The names of most of these should be self-explanatory.
int_of_float: float -> int float_of_int: int -> float int_of_string: string -> int string_of_int: int -> string float_of_string: string -> float string_of_float: float -> string print_int: int -> unit print_int_newline: int -> unit print_float: float -> unit print_float_newline: float -> unit print_string: string -> unit print_string_newline: string -> unit print_newline: unit -> unit same_string: string -> string -> bool (* Array operations *) empty: int -> α -> α array get: α array -> int -> α set: α array -> int -> unit arraylength: α array -> int |