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.

corresponding computed solution is<br />

{x=0,y=0} | {x=2,y=4}<br />

4.1.5 Floating Point Numbers<br />

Similarly to integers, values like “3.14159” or “5.0e-4” are considered as constructors of type Float.<br />

Since overloading is not included in the kernel version of <strong>Curry</strong>, the names of arithmetic functions<br />

on floats are different from the corresponding functions on integers.<br />

4.1.6 Lists<br />

The type [t] denotes all lists whose elements are values of type t. The type of lists can be<br />

considered as predefined by the declaration<br />

data [a] = [] | a : [a]<br />

where [] denotes the empty list and x:xs is the non-empty list consisting of the first element x<br />

and the remaining list xs. Since it is common to denote lists with square brackets, the following<br />

convenient notation is supported:<br />

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

denotes the list e1:e2:· · ·:en:[] (which is equivalent to e1:(e2:(· · ·:(en:[])...)) since “:” is a<br />

right-associative infix operator). Note that there is an overloading in the notation [t]: if t is a<br />

type, [t] denotes the type of lists containing elements of type t, where [t] denotes a single element<br />

list (with element t) if t is an expression. Since there is a strong distinction between occurrences<br />

of types and expressions, this overloading can always be resolved.<br />

For instance, the following predefined functions define the concatenation of two lists and the<br />

application of a function to all elements in a list:<br />

(++) :: [a] -> [a] -> [a]<br />

[] ++ ys = ys<br />

(x:xs) ++ ys = x : xs ++ ys<br />

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

map f [] = []<br />

map f (x:xs) = f x : map f xs<br />

4.1.7 Characters<br />

Values like ’a’ or ’0’ denote constants of type Char. There are two conversion functions between<br />

characters and their corresponding ASCII values:<br />

ord :: Char -> Int<br />

chr :: Int -> Char<br />

17

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

Saved successfully!

Ooh no, something went wrong!