Syntax

The syntax of Cayenne is very close to that of Haskell.

Lexical structure

Identifiers

Identifiers consist of an initial letter optionally followed by more letters, digits, single quote ('), or dollar sign ($). If an identifier contains a dollar sign it is a module identifier and it can only be used to name modules.

Some normal identifiers: x, x', foo, Bool.
Some module identifiers: foo$bar, System$Bool

Reserved words

Some identifiers are reserved words and cannot be used as variables:
abstract, case, concrete, data, do, in, interface, let, module
of, open, native, private, public, sig, struct, type, use

Operators

Operators are built from a sequence of the characters:
! @ # $ % & * + . / < = > ? \ ^ | : - ~ ,
¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ
¶ · ¸ ¹ º » ¼ ½ ¾ ¿ × ÷
An operators can be used where a variable is needed by enclosing it in parenthesis.

Reserved operators

Some operators are reserved:
::, =, @, \, |, #, ->, |->, ., <-

Operator precedences

There is a fixed set of operator precedences:
OperatorAssociativityPrecedence
->,|->right0
===none1
,left1
||right2
&&right3
==,/=,<=,>=,<,> none4
:,++right5
+,-left6
*,/left7
·right8
otherleft9

Literals

Numeric literals

Numeric literals consist of a (nonempty) sequence of digits, as in 4711.

Numeric literals have type System$Int.Int.

Character literals and String literals

Character literals are written between single quotes, as in 'a', and strings between double quotes, as in "Hello".

Escape codes may be used in characters and strings to represent special characters. Note that a single quote ' may be used in a string, but must be escaped in a character; similarly, a double quote " may be used in a character, but must be escaped in a string. \ must always be escaped. The category charesc also includes portable representations for the characters "alert" (\a), "backspace" (\b), "form feed" (\f), "new line" (\n), "carriage return" (\r), "horizontal tab" (\t), and "vertical tab" (\v).

Character literals have type System$Char.Char and string literals System$String.String.

Layout

Cayenne uses the same kind of layout rule as Haskell. In syntactic construct with of the form { item; ... } the curly braces and semicolons can be replaced by layout.

Back


Lennart Augustsson
Last modified: Mon Aug 31 01:39:59 CEST 1998