The abstract syntax shown below describes the precise structure of FlatCurry programs. Comments on the different syntactic entities in this syntax can be found in the document type definition (DTD) for an external representation of FlatCurry programs. Examples showing the translation of functions defined by pattern matching into FlatCurry can be found here.
| prog | ::= | module import* type* function* operator* translation* | (complete program module) |
| module | ::= | ident | (name of the module) |
| import | ::= | module | (name of imported module) |
| type | ::= | t(typevar*,consdecl*) | (declaration of data type "t") |
| consdecl | ::= | c(arity,typeexpr*) | (declaration of data constructor "c") |
| arity | ::= | <natural number> | |
| typeexpr | ::= | typevar | (type variable) |
| | | typeexpr -> typeexpr | (function type) | |
| | | t(typeexpr*) | (type constructor application) | |
| typevar | ::= | tvar(<integer>) | (type variables have unique indices) |
| function | ::= | f(arity,typeexpr,rule) | (declaration of function "f") |
| rule | ::= | lhs -> expr | (rule for user-defined function) |
| | | external(<string>) | (name of external function) | |
| lhs | ::= | var* | (left-hand side is list of variables) |
| expr | ::= | var | (variable) |
| | | <integer> | <float> | char(<integer>) | (constant literal) | |
| | | c(expr*) | (constructor application) | |
| | | f(expr*) | (function application) | |
| | | case expr of {pat -> expr ;...; pat -> expr} | (rigid case expression) | |
| | | fcase expr of {pat -> expr ;...; pat -> expr} | (flexible case expression) | |
| | | or(expr,expr) | (disjunction) | |
| | | partcall(f,expr*) | (partial function/constructor application) | |
| | | apply(expr,expr) | (application) | |
| | | constr(var*,expr) | (constraint with existentially quantified variables) | |
| | | guarded(var*,expr,expr) | (guarded expression) | |
| | | choice(expr) | (comitted choice) | |
| | | let(binding*,expr) | ((non-recursive) let binding of variables) | |
| | | letrec(binding*,expr) | (recursive let binding of variables) | |
| var | ::= | var(<integer>) | (variables have unique indices) |
| pat | ::= | c(var*) | (shallow pattern with fresh variables) |
| | | <integer> | <float> | char(<integer>) | (literal constant as pattern) | |
| binding | ::= | var = expr | (local variable binding) | operator | ::= | op(fixity,precedence) | (infix operator declaration) |
| fixity | ::= | infix | infixl | infixr | |
| precedence | ::= | 0 | 1 | ... | 9 | |
| translation | ::= | (ident,ident) | (translation of external to internal names) |
| ident | ::= | <string> |