Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
10 Literate Programming<br />
To encourage the use of comments for the documentation of programs, <strong>Curry</strong> supports a literate<br />
programming style (inspired by Donald Knuth’s “literate programming”) where comments are the<br />
default case. Non-comment lines containing program code must start with “>” followed by a blank.<br />
Using this style, we can define the concatenation and reverse function on lists by the following<br />
literate program:<br />
The following function defines the concatenation of two lists.<br />
Note that this function is predefined as ‘++’ in the standard prelude.<br />
> append :: [t] -> [t] -> [t]<br />
> append [] x = x<br />
> append (x:xs) ys = x : append xs ys<br />
As a second example for list operations, we define a<br />
function to reverse the order of elements in a list:<br />
> rev :: [t] -> [t]<br />
> rev [] = []<br />
> rev (x:xs) = append (rev xs) [x]<br />
To distinguish literature from non-literate programs, literate programs must be stored in files<br />
with the extension “.lcurry” whereas non-literate programs are stored in files with the extension<br />
“.curry”.<br />
11 Interactive Programming Environment<br />
In order to support different implementations with a comparable user interface, the following commands<br />
should be supported by each interactive programming environment for <strong>Curry</strong> (these commands<br />
can also be abbreviated to :c where c is the first character of the command):<br />
:load file Load the program stored in file.curry.<br />
:reload Repeat the last load command.<br />
expr Evaluate the expression expr and show all computed results. Since an expression could<br />
be evaluated to a disjunctive expression (cf. Section 3), the expression could be automatically<br />
wrapped in some search operator like depth-first search or a fair breadth-first search,<br />
depending on the implementation.<br />
:debug expr Debug the evaluation of the expression expr, i.e., show the single computation steps<br />
and ask the user what to do after each single step (like proceed, abort, etc.).<br />
:type expr Show the type of the expression expr.<br />
36