Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > Clean programming language


 

Clean is a purely functional programming language that, in some respects, is similar to the better-known Haskell programming language.

Clean has several advantages as a programming language. It features a uniqueness type system, which allows a purely functional way of dealing with resources such as I/O that cannot be duplicated. Clean also has a list comprehension system which can create queries at least as complex as SQL can handle. Clean also uses a more compact format for conditionals. Clean has a very simple and easy-to-use IDE that writes only the project files, not the actual programs. Clean programs are extremely portable; in almost all cases, porting to a different platform simply means a recompile.

The hello world program for Clean is shown below:

module hello Start :: String Start = "Hello, world!"

The first line, module hello, tells the compiler that that this module, or part of a project, is called "hello". It has to be stored in a file called hello.icl unless you want to change that line of code. The next line, Start :: String, says that the variable Start, which is the first thing the compiler evaluates, is of the String type. The last line sets the variable Start to "Hello, world!". Since no other output method, such as a GUI, is declared, the words "Hello, world!" just appear in a console box.

Clean is based on the mathematical principle of graph rewriting . Constants such as numbers are graphs, and functions are graph rewriting formulas. Clean programs are evaluated using the well-understood technique of reduction, which essentially reduces everything to a very simple form. Reduction makes programs implemented in Clean relatively fast, even with the high abstraction of the language.

Clean has a very unique compiling system. First, source files (.icl) and project files (.dcl) are converted into Clean's own bytecode (.abc files). This is implemented in C and Clean . The bytecode is completely platform-independent, but it cannot be run. Next, this bytecode is converted to object code (.obj) using C. After that, the object code is linked with other files in the module and the runtime system and converted into a normal executable (done in Clean). Although it seems like there would be bootstrapping issues with this, they are resolved because earlier versions of the Clean system were written completely in C.

Clean was produced and is mantained by the Radboud University Nijmegen. The IDE was written by the Dutch-based company Hilt. It is available for the platforms Windows, Macintosh, Solaris, and Linux, but input-output capabilities are limited on Linux. It is licensed under the GNU LGPLThe GNU Lesser General Public License (formerly the GNU Library General Public License is an FSF approved Free Software license designed as a compromise between the GNU General Public License and simple permissive licenses such as the BSD license and the, but it can be used without the LGPL if it is bought for €495. Clean is not developed with an open sourceNote: "open source" in the intelligence community simply means "any information accessible to the public, possibly after paying a fee". This article is about open source software, a more common meaning for the term "open source". Open source or open sourc development model, though.

Although Clean isn't used much commercially, it is used extensively in research.

1 Overview

Here is an implementation of the factorial function in Clean:

fac :: Int -> Int fac 0 = 1 fac n = n * fac (n-1)

The first line defines the type of the function: an integer as argument and an integer as a result. The second line defines the case when the argument is the constant 0. The second one defines how fact should be computed for an arbitrary n. Note that, in Clean, the first alternative that matches the actual arguments will be used, that is, the order of the cases is important in Clean. The alternative, supposed by several other languages, is to disregard the ordering of the cases, thus requiring that each alternative be disjoint so that only one is applicable in each possible situation.

Each program in Clean computes the value of the expression Start. By providing an appropriate definition for the function Start, the value of any expression can be computed. Thus, the "Hello world"-program is just:

Start :: String Start = "Hello world"

An infix operator is defined just like every other function except: the type of the function indicates that it is an infix operator, and the operator itself is written whithin parenthesis:

(^) infixr 8 :: Int Int -> Int (^) x 0 = 1 (^) x n = x * x ^ (n-1)

The infixr type declaration states that the function is a right associative infix operator with priority 8 (this priority level implies that there are no parenthesis needed in the body of the second case of the operator definition to distinguish (x*x)^(n-1) and x*(x^(n-1)) (the (^) operator is pre-defined as a type class in the Clean standard environment.)



Read more »

Non User