Clean | |
Paradigm: | functional |
Designer: | Software Technology Research Group of Radboud University Nijmegen |
Latest Release Version: | 3.1 |
Typing: | strong, static, dynamic |
Operating System: | Cross-platform |
License: | Simplified BSD[1] |
Influenced By: | Lean, Miranda, Haskell |
Influenced: | Haskell, Idris[2] |
File Ext: | .icl, .dcl, .abc |
Clean is a general-purpose purely functional programming language. Originally called the Concurrent Clean System[3] or the Clean System,[4] [5] it has been developed by a group of researchers from the Radboud University in Nijmegen since 1987.[6] [7] Although development of the language has slowed, some researchers are still working in the language.[8] In 2018, a spin-off company was founded that uses Clean.[9]
Clean shares many properties and syntax with a younger sibling language, Haskell: referential transparency, list comprehension, guards, garbage collection, higher order functions, currying, and lazy evaluation. However, Clean deals with mutable state and input/output (I/O) through a uniqueness type 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 at any point during the execution of the program, only one reference can exist to a value with a unique type. Therefore, a unique value can be changed in place.[10]
An integrated development environment (IDE) for Microsoft Windows is included in the Clean distribution.
Hello world
Start = fac 10 | Start = fac 10 |
Start = fib 7 | fib :: Int -> Intfib n = (fibs 1 1) ! | n Start = fib 7 |
---|
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.Computing is based on graph rewriting and reduction. Constants such as numbers are graphs and functions are graph rewriting formulas. This, combined with compiling to native code, makes Clean programs which use high abstraction run relatively fast according to The Computer Language Benchmarks Game.[11] A 2008 benchmark showed that Clean native code performs similarly to the Glasgow Haskell Compiler (GHC), depending on the benchmark.[12]
Compilation of Clean to machine code is performed as follows:
Earlier versions of the Clean compiler were written completely in C, thus avoiding bootstrapping issues.
The ABC code mentioned above is an intermediate representation for an abstract machine. Because machine code generation for ABC code is relatively straightforward, it is easy to support new architectures. The ABC machine is an imperative abstract graph rewriting machine.[13] It consists of a graph store to hold the Clean graph that is being rewritten and three stacks:
The runtime system, which is linked into every executable, builds a Start
node in the graph store and pushes it on the A-stack. It then begins printing it, evaluating it as needed.
Although Clean is typically used to generate native executables, several projects have enabled applications in web browsers.The now abandoned SAPL project compiled Core Clean to JavaScript and did not use ABC code. Since 2019, an interpreter for ABC code, written in WebAssembly, is used instead.[14] [15]
Clean is available for Microsoft Windows (IA-32 and X86-64), macOS (X86-64), and Linux (IA-32, X86-64, and AArch64).
Some libraries are not available on all platforms, like ObjectIO which is only available on Windows. Also the feature to write dynamics to files is only available on Windows.
The availability of Clean per platform varies with each version:[16] [17]
Version | Date | Linux | macOS | Oracle Solaris | Windows | Miscellaneous | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
IA-32 | x86-64 | AArch64 | Motorola 68040 | PowerPC | x86-64 | SPARC | IA-32 | x86-64 | ||||
3.1 | ||||||||||||
3.0 | ||||||||||||
2.4 | ||||||||||||
2.3 | ||||||||||||
2.2 | ||||||||||||
2.1.1 | ||||||||||||
2.1.0 | ||||||||||||
2.0.2 | ||||||||||||
2.0.1 | ||||||||||||
2.0 | ||||||||||||
1.3.3 | ||||||||||||
1.3.2 | ||||||||||||
1.3.1 | ||||||||||||
1.3 | ||||||||||||
1.2.4 | ||||||||||||
1.2.3 | ||||||||||||
1.2 | ||||||||||||
1.1.3 | OS/2 (i80386) | |||||||||||
1.1.2 | SunOS 4 (SPARC) | |||||||||||
1.1 | ||||||||||||
1.0.2 | OS/2 (i80386); SunOS 4 (SPARC) | |||||||||||
1.0 | OS/2 (i80386) | |||||||||||
0.8.4 | Experimental T800 transputer release | |||||||||||
0.8.3 | ||||||||||||
0.8.1 | ||||||||||||
0.8 | OS/2 (i80386); SunOS 3–4 (SPARC) | |||||||||||
0.7 | SunOS 3–4 (SPARC) |
The syntax of Clean is very similar to that of Haskell, with some notable differences. In general, Haskell has introduced more syntactic sugar than Clean:
Haskell | Clean | Remarks | ||
---|---|---|---|---|
list comprehension | ||||
cons operator | ||||
Node (Tree a) a (Tree a) | Tree a = Empty | Node (Tree a) a (Tree a) | algebraic data type | |
Eq a & Eq b | class assertions and contexts | |||
as-patterns | ||||
if |
public registry with Clean packages
a search engine to search in Clean packages