The Clean system is a powerful functional programming tool. It contains experiments in a number of different areas of functional language design. In particular, it has a novel proposal for the organization of input and output , and contains impressive libraries of facilities for programming graphical user interfaces . Clean I/O is based on collections of operations that act to cause side effects on multiple explicit abstract values representing physical I/O entities, such as files and graphical interfaces. A system of unique types is used to ensure that these values are individually single threaded through the program; and the side effecting I/O operations are therefore well controlled. This approach is distinct from monadic I/O, which is being widely adopted; monadic I/O schemes are based on a single, implicit environment , and guarantee that this is single threaded. In this paper we will show that the Clean and monadic approaches to I/O merge nicely. The functionality provided by the Clean and its I/O libraries allows libraries for monadic I/O to be implemented. The paper presents an implementation of a basic I/O monad library in Clean that can serve for future development. In itself, the fact that the monadic approach can be implemented in Clean is unsurprising. However, some interesting technical difficulties arose during implementation of the monad; these and their solutions are discussed. The opportunity to express programs using the implicit environments of monadic I/O allows us to simplify Clean programs by removing some of the spaghetti, whilst retaining the generality of the explicit environments where it is the most appropriate approach.
Author and article information
Simon B Jones
Department of Computing Science and Mathematics, University of Stirling