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.

Now the names f, m1.f, and m2.f refer to the identical entity, namely the function f defined<br />

in module m. Note that there is no need to qualify f in the module main since this name is<br />

unambiguously resolved to the function f defined in module m, although it is imported via two<br />

different paths.<br />

Qualified names are treated syntactically like unqualified names. In particular, a qualified infix<br />

operator like Complex.+ has the same fixity as the definition of + in the module Complex, i.e., the<br />

expression “x Complex.+ y” is syntactically valid. To distinguish between a function composition<br />

like “f . g”, where “.” is an infix operator (see Section 14, page 46), and a module qualification,<br />

spaces are not allowed in the module qualification while there must be at least one space before<br />

the “.” if it is used as an infix operator. Thus, “f . g” is interpreted as the composition of f and<br />

g whereas “f.g” is interpreted as the object g imported from module f.<br />

The import dependencies between modules must be non-circular, i.e., it is not allowed that<br />

module m1 imports module m2 and module m2 also imports (directly or indirectly) module m1.<br />

7 Input/Output<br />

<strong>Curry</strong> provides a declarative model of I/O by considering I/O operations as transformations on<br />

the outside world. In order to avoid dealing with different versions of the outside world, it must<br />

be ensured that at each point of a computation only one version of the world is accessible. This is<br />

guaranteed by using the monadic I/O approach [42] of Haskell and by requiring that I/O operations<br />

are not allowed in program parts where non-deterministic search is possible.<br />

7.1 Monadic I/O<br />

In the monadic I/O approach, the outside “world” is not directly accessible but only through actions<br />

which change the world. Thus, the world is encapsulated in an abstract datatype which provides<br />

actions to change the world. The type of such actions is IO t which is an abbreviation for<br />

World -> (t,World)<br />

where World denotes the type of all states of the outside world. If an action of type IO t is applied<br />

to a particular world, it yields a value of type t and a new (changed) world. For instance, getChar<br />

is an action which reads a character from the standard input when it is executed, i.e., applied to<br />

a world. Therefore, getChar has the type IO Char. The important point is that values of type<br />

World are not accessible for the programmer — she/he can only create and compose actions on<br />

the world. Thus, a program intended to perform I/O operations has a sequence of actions as the<br />

result. These actions are computed and executed when the program is connected to the world by<br />

executing it. For instance,<br />

getChar :: IO Char<br />

getLine :: IO String<br />

are actions which read the next character or the next line from the standard input. The functions<br />

putChar :: Char -> IO ()<br />

putStr :: String -> IO ()<br />

putStrLn :: String -> IO ()<br />

27

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

Saved successfully!

Ooh no, something went wrong!