|Designed by||Software Technology Research Group of Radboud University Nijmegen|
3.0 / October 19, 2018
|Typing discipline||strong, static, dynamic|
|Filename extensions||.icl, .dcl, .abc|
|Lean, Miranda, Haskell|
Clean is a general-purpose purely functional computer programming language. For much of the language's active development history it was called Concurrent Clean, but this was dropped at some point.[vague] Clean is being developed by a group of researchers from the Radboud University in Nijmegen since 1987.
The language Clean first appeared in 1987 and is still being further developed. It shares many properties with Haskell: referential transparency, list comprehension, guards, garbage collection, higher order functions, currying and lazy evaluation.
Clean deals with mutable state and I/O through a uniqueness typing system, in contrast to Haskell's use of monads. The compiler takes advantage of the uniqueness type system to generate more efficient code, because it knows that anything with a uniqueness type can only be used once. Therefore, a unique value can be changed in place.
Start = "Hello, world!"
fac :: Int -> Int fac 0 = 1 fac n = n * fac (n-1) Start = fac 10
fac :: Int -> Int fac n = prod [1..n] // The product of the numbers 1 to n Start = fac 10
fib :: Int -> Int fib 0 = 1 fib 1 = 1 fib n = fib (n - 2) + fib (n - 1) Start = fib 7
fibs :: Int Int -> [Int] fibs x_2 x_1 = [x_2:fibs x_1 (x_2 + x_1)] fib :: Int -> Int fib n = (fibs 1 1) !! n Start = fib 7
(^) infixr 8 :: Int Int -> Int (^) x 0 = 1 (^) x n = x * x ^ (n-1)
The type declaration states that the function is a right associative infix operator with priority 8: this states that
x*x^(n-1) is equivalent to
x*(x^(n-1)) as opposed to
(x*x)^(n-1). This operator is pre-defined in StdEnv, the Clean standard library.
Computation is based on graph rewriting and reduction. Constants such as numbers are graphs and functions are graph rewriting formulas. This, combined with compilation to native code, makes Clean programs which use high abstraction run relatively fast according to the Computer Language Benchmarks Game.
Earlier Clean system versions were written completely in C, thus avoiding bootstrapping issues.
To close the gap between Core Clean, a high-level functional language, and machine code, the ABC machine is used. This is an imperative abstract graph rewriting machine. Generating concrete machine code from abstract ABC code is a relatively small step, so by using the ABC machine it is much easier to target multiple architectures for code generation.
The ABC machine has an uncommon memory model. It has a graph store to hold the Clean graph that is being rewritten. The A(rgument)-stack holds arguments that refer to nodes in the graph store. This way, a node's arguments can be rewritten, which is needed for pattern matching. The B(asic value)-stack holds basic values (integers, characters, reals, etc.). While not strictly necessary (all these elements could be nodes in the graph store as well), using a separate stack is much more efficient. The C(ontrol)-stack holds return addresses for flow control.
The runtime system, which is linked into every executable, has a
Start node is printed. For this, it has to be rewritten to root normal form, after which its children are rewritten to root normal form, etc., until the whole node is printed.
Some libraries are not available on all platforms, like ObjectIO which is only available on Windows and Mac. The feature to write dynamics to files is only available on Windows.
The syntax of Clean is very similar to that of Haskell, with some notable differences:
[ x | x <- [1..10] , isOdd x]
[ x \\ x <- [1..10] | isOdd x]
data Tree a = Empty | Node (Tree a) a (Tree a)
:: Tree a = Empty | Node (Tree a) a (Tree a)
|algebraic data type|
(Eq a, Eq b) => ...
... | Eq a & Eq b
|class assertions and contexts|
fun t@(Node l x r) = ...
fun t=:(Node l x r) = ...
if x > 10 then 10 else x
if (x > 10) 10 x
In general, Haskell has introduced more syntactic sugar than Clean.
Edited: 2021-06-18 18:12:24