| Clean | |
|---|---|
| Paradigm | functional |
| Designed by | Software Technology Research Group ofRadboud University Nijmegen |
| First appeared | 1987; 39 years ago (1987) |
| Stable release | 3.1 / 5 January 2022; 4 years ago (2022-01-05) |
| Typing discipline | strong,static,dynamic |
| OS | Cross-platform |
| License | Simplified BSD[1] |
| Filename extensions | .icl, .dcl, .abc |
| Website | clean |
| Influenced by | |
| Lean,Miranda,Haskell | |
| Influenced | |
| Haskell,Idris[2] | |
Clean is ageneral-purposepurely functionalprogramming language. Originally called theConcurrent Clean System[3] or theClean System,[4][5] it has been developed by a group of researchers from theRadboud 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 andsyntax with a younger sibling language,Haskell:referential transparency,list comprehension,guards,garbage collection,higher order functions,currying, andlazy evaluation. However, Clean deals with mutable state andinput/output (I/O) through auniqueness type system, in contrast to Haskell's use ofmonads. Thecompiler 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 bechanged in place.[10]
Anintegrated development environment (IDE) forMicrosoft Windows is included in the Clean distribution.
Start="Hello, world!"
fac::Int->Intfac0=1facn=n*fac(n-1)Start=fac10 | fac::Int->Intfacn=prod[1..n]// The product of the numbers 1 to nStart=fac10 |
fib::Int->Intfib0=1fib1=1fibn=fib(n-2)+fib(n-1)Start=fib7 | fibs::IntInt->[Int]fibsx_2x_1=[x_2:fibsx_1(x_2+x_1)]fib::Int->Intfibn=(fibs11)!!nStart=fib7 |
Infix operator:
(^)infixr8::IntInt->Int(^)x0=1(^)xn=x*x^(n-1)
The type declaration states that the function is a right associative infix operator with priority 8: this states thatx*x^(n-1) is equivalent tox*(x^(n-1)) as opposed to(x*x)^(n-1). This operator is pre-defined in StdEnv, the Cleanstandard library.
Computing is based ongraph rewriting andreduction. 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 toThe Computer Language Benchmarks Game.[11] A 2008benchmark showed that Clean native code performs similarly to theGlasgow Haskell Compiler (GHC), depending on the benchmark.[12]
Compilation of Clean tomachine code is performed as follows:
Earlier versions of the Clean compiler were written completely inC, thus avoiding bootstrapping issues.
The ABC code mentioned above is anintermediate representation for anabstract machine. Because machine code generation for ABC code is relatively straightforward, it is easy to support new architectures. The ABC machine is animperative abstractgraph rewriting machine.[13] It consists of a graph store to hold the Clean graph that is being rewritten and three stacks:
Theruntime system, which is linked into every executable, builds aStart 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 inweb browsers.The now abandonedSAPL project compiled Core Clean toJavaScript and did not use ABC code. Since 2019, an interpreter for ABC code, written inWebAssembly, is used instead.[14][15]
Clean is available forMicrosoft Windows (IA-32 andX86-64),macOS (X86-64), andLinux (IA-32,X86-64, andAArch64).[citation needed]
Some libraries are not available on all platforms, likeObjectIO which is only available on Windows. Also the feature to write dynamics to files is only available on Windows.[citation needed]
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 | 5 January 2022 | Yes | Yes | Yes | No | No | Yes | No | Yes | Yes | |
| 3.0 | 2 October 2018 | Yes | Yes | No | No | No | Yes | No | Yes | Yes | |
| 2.4 | 23 December 2011 | Yes | Yes | No | No | No | Yes | No | Yes | Yes | |
| 2.3 | 22 December 2010 | Yes | Yes | No | No | No | No | No | Yes | Yes | |
| 2.2 | 19 December 2006 | Yes | Yes | No | No | Yes | No | Yes | Yes | Yes | |
| 2.1.1 | 31 May 2005 | Yes | No | No | No | Yes | No | Yes | Yes | No | |
| 2.1.0 | 31 October 2003 | Yes | No | No | No | Yes | No | Yes | Yes | No | |
| 2.0.2 | 12 December 2002 | Yes | No | No | No | Yes | No | Yes | Yes | No | |
| 2.0.1 | 4 July 2002 | Yes | No | No | No | Yes | No | Yes | Yes | No | |
| 2.0 | 21 December 2001 | No | No | No | No | No | No | No | Yes | No | |
| 1.3.3 | 13 September 2000 | Yes | No | No | No | Yes | No | Yes | Yes | No | |
| 1.3.2 | 1 July 1999 | No | No | No | Yes | Yes | No | Yes | Yes | No | |
| 1.3.1 | January 1999 | Yes | No | No | No | Yes | No | Yes | Yes | No | |
| 1.3 | 22 May 1998 | Yes | No | No | No | Yes | No | Yes | Yes | No | |
| 1.2.4 | June 1997 | No | No | No | Yes | Yes | No | No | Yes | No | |
| 1.2.3 | May 1997 | No | No | No | Yes | Yes | No | No | Yes | No | |
| 1.2 | 13 January 1997 | No | No | No | Yes | Yes | No | No | No | No | |
| 1.1.3 | October 1996 | No | No | No | No | No | No | Yes | No | No | OS/2 (i80386) |
| 1.1.2 | September 1996 | Yes | No | No | No | No | No | Yes | No | No | SunOS 4 (SPARC) |
| 1.1 | March 1996 | Yes | No | No | Yes | No | No | No | No | No | |
| 1.0.2 | September 1995 | Yes | No | No | Yes | No | No | Yes | No | No | OS/2 (i80386);SunOS 4 (SPARC) |
| 1.0 | May 1995 | No | No | No | Yes | No | No | No | No | No | OS/2 (i80386) |
| 0.8.4 | 11 May 1993 | Yes | No | No | Yes | No | No | No | No | No | ExperimentalT800 transputer release |
| 0.8.3 | 26 February 1993 | No | No | No | Yes | No | No | No | No | No | |
| 0.8.1 | 19 October 1992 | No | No | No | Yes | No | No | No | No | No | |
| 0.8 | 13 July 1992 | No | No | No | Yes | No | No | No | No | No | OS/2 (i80386);SunOS 3–4 (SPARC) |
| 0.7 | May 1991 | No | No | No | Yes | No | No | No | No | No | SunOS 3–4 (SPARC) |
The syntax of Clean is very similar to that of Haskell, with some notable differences. In general, Haskell has introduced moresyntactic sugar than Clean:[10]
| Haskell | Clean | Remarks |
|---|---|---|
[x|x<-[1..10],isOddx] | [x\\x<-[1..10]|isOddx] | list comprehension |
x:xs | [x:xs] | cons operator |
dataTreea=Empty|Node(Treea)a(Treea) | ::Treea=Empty|Node(Treea)a(Treea) | algebraic data type |
(Eqa,Eqb)=>... | ...|Eqa&Eqb | class assertions and contexts |
funt@(Nodelxr)=... | funt=:(Nodelxr)=... | as-patterns |
ifx>10then10elsex | if(x>10)10x | if |
{{cite web}}: CS1 maint: bot: original URL status unknown (link)