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.

g :: [a] -> [b] -> ([a],[b])<br />

g x y = (f x, f y)<br />

h :: ([Int],[Bool])<br />

h = g [3,4] [True,False]<br />

However, if the type declaration for g is omitted, the usual type inference algorithms are not able<br />

to infer this type.<br />

5 Expressions<br />

Expressions are a fundamental notion of <strong>Curry</strong>. As introduced in Section 2, functions are defined<br />

by equations defining expressions that are equivalent to specific function calls. For instance, the<br />

program rule<br />

square x = x*x<br />

defines that the function call (square 3) is equivalent to the expression (3*3).<br />

Expressions occur in conditions and right-hand sides of equations defining functions. A computation<br />

evaluates an expression to a data term (see Section 3). Expressions are built from constants<br />

of a specific data type (e.g., integer constants, character constants, see Section 4), variables, or applications<br />

of constructors or functions to expressions. Furthermore, <strong>Curry</strong> provides some syntactic<br />

extensions for expressions that are discussed in this section.<br />

5.1 Arithmetic Sequences<br />

<strong>Curry</strong> supports two syntactic extensions to define list of elements in a compact way. The first one<br />

is a notation for arithmetic sequences. The arithmetic sequence<br />

[ e1 , e2 .. e3 ]<br />

denotes a list of integers starting with the first two elements e1 and e2 and ending with the element<br />

e3 (where e2 and e3 can be omitted). The precise meaning of this notation is defined by the<br />

following translation rules:<br />

Arithmetic sequence notation: Equivalent to:<br />

[e .. ] enumFrom e<br />

[e1,e2 .. ] enumFromThen e1 e2<br />

[e1 .. e2] enumFromTo e1 e2<br />

[e1,e2 .. e3] enumFromThenTo e1 e2 e3<br />

The functions for generating the arithmetic sequences, enumFrom, enumFromThen, enumFromTo, and<br />

enumFromThenTo, are defined in the prelude (see page 53). Thus, the different notations have the<br />

following meaning:<br />

• The sequence [e..] denotes the infinite list [e,e+1,e+2,...].<br />

20

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

Saved successfully!

Ooh no, something went wrong!