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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

language (however, implementations of <strong>Curry</strong> can choose more efficient implementation techniques).<br />

For instance, the function<br />

swap z = case z of<br />

[x,y] -> [y,x]<br />

_ -> z<br />

is equivalent to the following definition:<br />

swap eval rigid<br />

swap [] = []<br />

swap [x] = [x]<br />

swap [x,y] = [y,x]<br />

swap (x1:x2:x3:xs) = x1:x2:x3:xs<br />

Thus, case expressions are a convenient notation for functions with default cases.<br />

6 Modules<br />

A module defines a collection of datatypes, constructors and functions which we call entities in the<br />

following. A module exports some of its entities which can be imported and used by other modules.<br />

<strong>An</strong> entity which is not exported is not accessible from other modules.<br />

A <strong>Curry</strong> program is a collection of modules. There is one main module which is loaded into a<br />

<strong>Curry</strong> system. The modules imported by the main module are implicitly loaded but not visible to<br />

the user. After loading the main module, the user can evaluate expressions which contain entities<br />

exported by the main module.<br />

There is one distinguished module, named prelude, which is implicitly imported into all programs<br />

(see also Appendix B). Thus, the entities defined in the prelude (basic functions for arithmetic,<br />

list processing etc.) can be always used.<br />

A module always starts with the head which contains at least the name of the module followed<br />

by the keyword where, like<br />

module stack where ...<br />

If a program does not contain a module head, the standard module head “module main where” is<br />

implicitly inserted. Module names can be given a hierarchical structure by inserting dots which is<br />

useful if larger applications should be structured into different subprojects. For instance,<br />

company.project1.subproject2.mod4<br />

is a valid module name. The dots may reflect the hierarchical file structure where modules<br />

are stored. For instance, the module compiler.symboltable could be stored in the file<br />

symboltable.curry in the directory compiler. To avoid such long module names when referring<br />

to entities of this module by qualification, imported modules can be renamed by the use of<br />

“as” in an import declaration (see below).<br />

Without any further restrictions in the module head, all entities which are defined by top-level<br />

declarations in this module are exported (but not those entities that are imported into this module).<br />

In order to modify this standard set of exported entities of a module, an export list can be added<br />

23

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

Saved successfully!

Ooh no, something went wrong!