14.11.2012 Views

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

QFunctionName ::= ( QInfixOpID ) | QFunctionID<br />

QInfixOpID ::= [ModuleID .] InfixOpID<br />

QFunctionID ::= [ModuleID .] FunctionID<br />

QVariableID ::= [ModuleID .] VariableID<br />

Literal ::= Int | Char | String | Float<br />

Int ::= see lexicon<br />

Char ::= see lexicon<br />

String ::= see lexicon<br />

Float ::= see lexicon<br />

If the alternative FunctionDeclaration is used in a ValueDeclaration, then the left-hand side<br />

(FunLHS) must have at least one pattern after the FunctionName (instead of zero patterns which<br />

is possible in top-level function declarations).<br />

In CondExprs, the first expression must have type Success or Bool. In the latter case, Boolean<br />

expressions in conditions are considered as an abbreviation for a (nested) if-then-else (see Section<br />

2.3.2).<br />

If the local definitions in a let expression contain at least one declaration of a free variable,<br />

the expression (after the keyword in) must be of type Success.<br />

In qualified names (e.g., QFunctionID), no characters (e.g., spaces) are allowed between the dot<br />

and the module and entity names. On the other hand, an infix expression (Expr QInfixOpID Expr)<br />

must contain at least one space or similar character after the left expression if the infix operator<br />

starts with a dot.<br />

C.4 Infix Operators<br />

In the grammar above, the use of infix operators in the rule for Expr is ambiguous. These ambiguities<br />

are resolved by assigning an associativity and precedence to each operator (InfixOpID)<br />

by a fixity declaration. There are three kinds of associativities, non-, left- and right-associativity<br />

(infix, infixl, infixr) and ten levels of precedence, 0 to 9, where level 0 binds least tightly<br />

and level 9 binds most tightly. All fixity declarations must appear at the beginning of a module.<br />

<strong>An</strong>y operator without an explicit fixity declaration is assumed to have the declaration infixl 9.<br />

For instance, the expression “1+2*3+4==x && b” is equivalent to “((((1+(2*3))+4)==x) && b)”<br />

w.r.t. the fixity declarations provided in the prelude.<br />

Note that the correct use of precedences and associativities excludes some expressions which<br />

are valid w.r.t. the context-free grammar. In general, the arguments of an infix operator must<br />

have an infix operator at the top with a higher precedence than the current infix operator (or no<br />

infix operator at the top). Additionaly, the left or right argument of a left- or right-associative<br />

operator can have a top infix operator with the same precedence. The unary minus operator is<br />

interpreted with precedence 6 which means that its argument must have a precedence of at least<br />

7. The expression “(- t)” is not considered as a right section but as the negation of t. As a<br />

consequence, the expressions “1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!