Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Clean (programming language)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Functional programming language}} {{Use dmy dates|date=March 2023}} {{Infobox programming language | name = Clean | logo = Clean 3.0 (programming language) logo.svg | paradigm = [[Functional programming|functional]] | designer = Software Technology Research Group of [[Radboud University Nijmegen]] | released = {{Start date and age|1987}} | latest release version = 3.1 | latest release date = {{Start date and age|2022|01|05|df=yes}} | typing = [[Strong and weak typing|strong]], [[Static typing|static]], [[Dynamic typing|dynamic]] | operating system = [[Cross-platform]] | license = [[Simplified BSD License|Simplified BSD]]<ref>{{cite web |title=Download Clean |url=https://clean.cs.ru.nl/Download_Clean#Clean_3.0_License |website=Clean |access-date=23 July 2019}}</ref> | influenced by = [https://foldoc.org/Lean Lean], [[Miranda (programming language)|Miranda]], [[Haskell]] | influenced = [[Haskell]], [[Idris (programming language)|Idris]]<ref>{{cite web|title=Idris - Uniqueness Types|url=http://docs.idris-lang.org/en/latest/reference/uniqueness-types.html|access-date=2018-11-20}}</ref> | file_ext = .icl, .dcl, .abc | website = {{URL|clean.cs.ru.nl}} }} '''Clean''' is a [[general-purpose programming language|general-purpose]] [[Purely functional programming|purely functional]] [[programming language]]. Originally called the '''Concurrent Clean System'''<ref>{{cite web |url=https://ftp.cs.ru.nl/Clean/old/Clean07/Sun4/README |title=Clean 0.7: Readme |archive-url=https://web.archive.org/web/20190524121044/https://ftp.cs.ru.nl/Clean/old/Clean07/Sun4/README |archive-date=2019-05-24}}</ref> or the '''Clean System''',<ref>{{cite web |url=https://ftp.cs.ru.nl/Clean/old/Clean10/README |title=Clean 1.0: Readme |archive-url=https://web.archive.org/web/20190505113256/https://ftp.cs.ru.nl/Clean/old/Clean10/README |archive-date=2019-05-05}}</ref><ref>{{cite web |url=https://ftp.cs.ru.nl/Clean/Clean13/README |title=Clean 1.3: Readme |archive-url=https://web.archive.org/web/20190427194714/https://ftp.cs.ru.nl/Clean/Clean13/README |archive-date=2019-04-27}}</ref> it has been developed by a group of researchers from the [[Radboud University]] in Nijmegen since 1987.<ref>{{cite web |url=https://www.mbsd.cs.ru.nl/Software |title=Radboud University Nijmegen: Department of Software Science: Software}}</ref><ref>{{cite web |url=http://wiki.clean.cs.ru.nl/FAQ |access-date=2021-11-26 |title=FAQ |website=Clean}}</ref> Although development of the language has slowed, some researchers are still working in the language.<ref>{{cite web |url=https://clean.cs.ru.nl/Publications |access-date=2021-11-26 |title=Publications |website=Clean}}</ref> In 2018, a spin-off company was founded that uses Clean.<ref>{{cite web |url=https://www.top-software.nl/ |title=Home |website=TOP Software Technology |access-date=26 November 2021}}</ref> ==Features== Clean shares many properties and [[Syntax (programming languages)|syntax]] with a younger sibling language, [[Haskell]]: [[referential transparency]], [[list comprehension]], [[Guard (computing)|guards]], [[Garbage collection (computer science)|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 [[Monad (functional programming)|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 [[destructive update|changed in place]].<ref name="CleanHaskellGuide">{{Cite FTP |url=ftp://ftp.cs.ru.nl/pub/Clean/papers/2007/achp2007-CleanHaskellQuickGuide.pdf |server=ftp.cs.ru.nl |url-status=dead |title=FTP link }}</ref> An [[integrated development environment]] (IDE) for [[Microsoft Windows]] is included in the Clean distribution. ==Examples== [[hello world program|Hello world]]: <syntaxhighlight lang="clean"> Start = "Hello, world!" </syntaxhighlight> [[Factorial]]: {| |-valign="bottom" |<syntaxhighlight lang="clean"> fac :: Int -> Int fac 0 = 1 fac n = n * fac (n-1) Start = fac 10 </syntaxhighlight> |<syntaxhighlight lang="clean"> fac :: Int -> Int fac n = prod [1..n] // The product of the numbers 1 to n Start = fac 10 </syntaxhighlight> |} [[Fibonacci sequence]]: {| |-valign="bottom" |<syntaxhighlight lang="clean"> fib :: Int -> Int fib 0 = 1 fib 1 = 1 fib n = fib (n - 2) + fib (n - 1) Start = fib 7 </syntaxhighlight> |<syntaxhighlight lang="clean"> 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 </syntaxhighlight> |} [[Infix notation|Infix]] operator: <syntaxhighlight lang="clean"> (^) infixr 8 :: Int Int -> Int (^) x 0 = 1 (^) x n = x * x ^ (n-1) </syntaxhighlight> The type declaration states that the function is a right associative infix operator with priority 8: this states that <code>x*x^(n-1)</code> is equivalent to <code>x*(x^(n-1))</code> as opposed to <code>(x*x)^(n-1)</code>. This operator is pre-defined in StdEnv, the Clean [[standard library]]. ==How Clean works== Computing is based on [[graph rewriting]] and [[graph reduction|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]].<ref name="benchmarks">{{cite web |title=Which programming languages are fastest? |url=http://shootout.alioth.debian.org/u32/which-programming-languages-are-fastest.php |website=Computer Language Benchmarks Game |url-status=bot: unknown |archive-url=https://web.archive.org/web/20110628185627/http://shootout.alioth.debian.org/u32/which-programming-languages-are-fastest.php |archive-date=28 June 2011}}</ref> A 2008 [[Benchmark (computing)|benchmark]] showed that Clean native code performs similarly to the [[Glasgow Haskell Compiler]] (GHC), depending on the benchmark.<ref>{{Cite FTP |last1=Jansen |first1=Jan Martin |last2=Koopman |first2=Pieter |last3=Plasmeijer |first3=Rinus |date=2008 |title=From Interpretation to Compilation |url=ftp://ftp.cs.ru.nl/pub/Clean/papers/2008/janj08-CEFP07-InterpretationToCompilation.pdf |server=FTP server |url-status=dead |access-date=2016-05-21}}</ref> ==Compiling== Compilation of Clean to [[machine code]] is performed as follows: # Source files (.icl) and definition files (.dcl) are translated into Core Clean, a basic variant of Clean, by the compiler frontend written in Clean. # Core clean is converted into Clean's platform-independent intermediate language (.abc), by the compiler backend written in Clean and [[C (programming language)|C]]. # Intermediate ABC code is converted to object code (.o) by the code generator written in [[C (programming language)|C]]. # Object code is linked with other files in the module and the runtime system and converted into a normal executable using the system [[Linker (computing)|linker]] (when available) or a dedicated linker written in Clean on [[Windows]]. Earlier versions of the Clean compiler were written completely in [[C (programming language)|C]], thus avoiding bootstrapping issues. === The ABC machine === 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 programming|imperative]] abstract [[graph rewriting]] machine.<ref>{{cite thesis|type=PhD|last1=Koopman|first1=Pieter|title=Functional Programs as Executable Specifications|date=10 December 1990|publisher=Katholieke Universiteit Nijmegen|isbn=90-9003689-X|page=35}}</ref> It consists of a graph store to hold the Clean graph that is being rewritten and three stacks: * The A(rgument)-stack holds arguments that refer to nodes in the graph store. * The B(asic value)-stack holds basic values (integers, characters, reals, etc.). Although these values could be nodes in the graph store, a separate stack is used for efficiency. * The C(ontrol)-stack holds return addresses for flow control. The [[runtime system]], which is linked into every executable, builds a <code>Start</code> node in the graph store and pushes it on the A-stack. It then begins printing it, evaluating it as needed. === Running Clean in the browser === Although Clean is typically used to generate native executables, several projects have enabled applications in [[web browser]]s. The now abandoned [https://clean.cs.ru.nl/SAPL 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.<ref>{{cite web |title=Clean and iTasks / ABC Interpreter Β· GitLab |url=https://gitlab.com/clean-and-itasks/abc-interpreter |website=Clean and iTasks on GitLab |access-date=13 April 2023 |language=en}}</ref><ref>{{cite book |last1=Staps |first1=Camil |last2=van Groningen |first2=John |last3=Plasmeijer |first3=Rinus |title=Proceedings of the 31st Symposium on Implementation and Application of Functional Languages |chapter=Lazy interworking of compiled and interpreted code for sandboxing and distributed systems |date=15 July 2021 |pages=1β12 |doi=10.1145/3412932.3412941|isbn=9781450375627 |s2cid=202751977 }}</ref> ==Platforms== Clean is available for [[Microsoft Windows]] ([[IA-32]] and [[X86-64]]), [[macOS]] ([[X86-64]]), and [[Linux]] ([[IA-32]], [[X86-64]], and [[AArch64]]).{{citation needed|date=September 2023}} 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.{{citation needed|date=September 2023}} The availability of Clean per platform varies with each version:<ref>{{cite web |title=Release history |url=https://clean.cs.ru.nl/Release_history |website=Clean |access-date=7 January 2022}}</ref><ref>{{cite web |title=Index of /Clean |url=https://ftp.cs.ru.nl/Clean/ |access-date=7 January 2022}}</ref> {| class="wikitable sortable" |- ! rowspan=2 | Version ! rowspan=2 | Date ! colspan=3 | [[Linux]] ! colspan=3 | [[macOS]] ! [[Oracle Solaris]] ! colspan=2 | [[Windows]] ! rowspan=2 | Miscellaneous |- ! [[IA-32]] ! [[x86-64]] ! [[AArch64]] ! [[Motorola 68040]] ! [[PowerPC]] ! [[x86-64]] ! [[SPARC]] ! [[IA-32]] ! [[x86-64]] |- | 3.1 || {{Date table sorting|5 January 2022}} | {{Yes}} || {{Yes}} || {{Yes}} | {{No}} || {{No}} || {{Yes}} | {{No}} | {{Yes}} || {{Yes}} | |- | 3.0 || {{Date table sorting|2 October 2018}} | {{Yes}} || {{Yes}} || {{No}} | {{No}} || {{No}} || {{Yes}} | {{No}} | {{Yes}} || {{Yes}} | |- | 2.4 || {{Date table sorting|23 December 2011}} | {{Yes}} || {{Yes}} || {{No}} | {{No}} || {{No}} || {{Yes}} | {{No}} | {{Yes}} || {{Yes}} | |- | 2.3 || {{Date table sorting|22 December 2010}} | {{Yes}} || {{Yes}} || {{No}} | {{No}} || {{No}} || {{No}} | {{No}} | {{Yes}} || {{Yes}} | |- | 2.2 || {{Date table sorting|19 December 2006}} | {{Yes}} || {{Yes}} || {{No}} | {{No}} || {{Yes}} || {{No}} | {{Yes}} | {{Yes}} || {{Yes}} | |- | 2.1.1 || {{Date table sorting|31 May 2005}} | {{Yes}} || {{No}} || {{No}} | {{No}} || {{Yes}} || {{No}} | {{Yes}} | {{Yes}} || {{No}} | |- | 2.1.0 || {{Date table sorting|31 October 2003}} | {{Yes}} || {{No}} || {{No}} | {{No}} || {{Yes}} || {{No}} | {{Yes}} | {{Yes}} || {{No}} | |- | 2.0.2 || {{Date table sorting|12 December 2002}} | {{Yes}} || {{No}} || {{No}} | {{No}} || {{Yes}} || {{No}} | {{Yes}} | {{Yes}} || {{No}} | |- | 2.0.1 || {{Date table sorting|4 July 2002}} | {{Yes}} || {{No}} || {{No}} | {{No}} || {{Yes}} || {{No}} | {{Yes}} | {{Yes}} || {{No}} | |- | 2.0 || {{Date table sorting|21 December 2001}} | {{No}} || {{No}} || {{No}} | {{No}} || {{No}} || {{No}} | {{No}} | {{Yes}} || {{No}} | |- | 1.3.3 || {{Date table sorting|13 September 2000}} | {{Yes}} || {{No}} || {{No}} | {{No}} || {{Yes}} || {{No}} | {{Yes}} | {{Yes}} || {{No}} | |- | 1.3.2 || {{Date table sorting|1 July 1999}} | {{No}} || {{No}} || {{No}} | {{Yes}} || {{Yes}} || {{No}} | {{Yes}} | {{Yes}} || {{No}} | |- | 1.3.1 || {{Date table sorting|January 1999}} | {{Yes}} || {{No}} || {{No}} | {{No}} || {{Yes}} || {{No}} | {{Yes}} | {{Yes}} || {{No}} | |- | 1.3 || {{Date table sorting|22 May 1998}} | {{Yes}} || {{No}} || {{No}} | {{No}} || {{Yes}} || {{No}} | {{Yes}} | {{Yes}} || {{No}} | |- | 1.2.4 || {{Date table sorting|June 1997}} | {{No}} || {{No}} || {{No}} | {{Yes}} || {{Yes}} || {{No}} | {{No}} | {{Yes}} || {{No}} | |- | 1.2.3 || {{Date table sorting|May 1997}} | {{No}} || {{No}} || {{No}} | {{Yes}} || {{Yes}} || {{No}} | {{No}} | {{Yes}} || {{No}} | |- | 1.2 || {{Date table sorting|13 January 1997}} | {{No}} || {{No}} || {{No}} | {{Yes}} || {{Yes}} || {{No}} | {{No}} | {{No}} || {{No}} | |- | 1.1.3 || {{Date table sorting|October 1996}} | {{No}} || {{No}} || {{No}} | {{No}} || {{No}} || {{No}} | {{Yes}} | {{No}} || {{No}} | [[OS/2]] ([[i80386]]) |- | 1.1.2 || {{Date table sorting|September 1996}} | {{Yes}} || {{No}} || {{No}} | {{No}} || {{No}} || {{No}} | {{Yes}} | {{No}} || {{No}} | [[SunOS]] 4 ([[SPARC]]) |- | 1.1 || {{Date table sorting|March 1996}} | {{Yes}} || {{No}} || {{No}} | {{Yes}} || {{No}} || {{No}} | {{No}} | {{No}} || {{No}} | |- | 1.0.2 || {{Date table sorting|September 1995}} | {{Yes}} || {{No}} || {{No}} | {{Yes}} || {{No}} || {{No}} | {{Yes}} | {{No}} || {{No}} | [[OS/2]] ([[i80386]]); [[SunOS]] 4 ([[SPARC]]) |- | 1.0 || {{Date table sorting|May 1995}} | {{No}} || {{No}} || {{No}} | {{Yes}} || {{No}} || {{No}} | {{No}} | {{No}} || {{No}} | [[OS/2]] ([[i80386]]) |- | 0.8.4 || {{Date table sorting|11 May 1993}} | {{Yes}} || {{No}} || {{No}} | {{Yes}} || {{No}} || {{No}} | {{No}} | {{No}} || {{No}} | Experimental [[Transputer#T8: floating point|T800 transputer]] release |- | 0.8.3 || {{Date table sorting|26 February 1993}} | {{No}} || {{No}} || {{No}} | {{Yes}} || {{No}} || {{No}} | {{No}} | {{No}} || {{No}} | |- | 0.8.1 || {{Date table sorting|19 October 1992}} | {{No}} || {{No}} || {{No}} | {{Yes}} || {{No}} || {{No}} | {{No}} | {{No}} || {{No}} | |- | 0.8 || {{Date table sorting|13 July 1992}} | {{No}} || {{No}} || {{No}} | {{Yes}} || {{No}} || {{No}} | {{No}} | {{No}} || {{No}} | [[OS/2]] ([[i80386]]); [[SunOS]] 3β4 ([[SPARC]]) |- | 0.7 || {{Date table sorting|May 1991}} | {{No}} || {{No}} || {{No}} | {{Yes}} || {{No}} || {{No}} | {{No}} | {{No}} || {{No}} | [[SunOS]] 3β4 ([[SPARC]]) |} ==Comparison to Haskell== 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:<ref name="CleanHaskellGuide" /> {| class="wikitable" border="1" |- ! Haskell ! Clean ! Remarks |- | <syntaxhighlight lang="haskell">[ x | x <- [1..10] , isOdd x]</syntaxhighlight> | <syntaxhighlight lang="clean">[ x \\ x <- [1..10] | isOdd x]</syntaxhighlight> | [[list comprehension]] |- | <syntaxhighlight lang="haskell">x:xs</syntaxhighlight> | <syntaxhighlight lang="clean">[x:xs]</syntaxhighlight> | [[cons]] operator |- | <syntaxhighlight lang="haskell"> data Tree a = Empty | Node (Tree a) a (Tree a) </syntaxhighlight> | <syntaxhighlight lang="clean"> :: Tree a = Empty | Node (Tree a) a (Tree a) </syntaxhighlight> | [[algebraic data type]] |- | <syntaxhighlight lang="haskell">(Eq a, Eq b) => ...</syntaxhighlight> | <syntaxhighlight lang="clean">... | Eq a & Eq b</syntaxhighlight> | class assertions and contexts |- | <syntaxhighlight lang="haskell">fun t@(Node l x r) = ...</syntaxhighlight> | <syntaxhighlight lang="clean">fun t=:(Node l x r) = ...</syntaxhighlight> | as-patterns |- | <syntaxhighlight lang="haskell">if x > 10 then 10 else x</syntaxhighlight> | <syntaxhighlight lang="clean">if (x > 10) 10 x</syntaxhighlight> | if |} ==References== {{Reflist}} ==External links== *[http://wiki.clean.cs.ru.nl/ Clean Wiki] *[https://clean-lang.org clean-lang.org]: public registry with Clean packages *[https://cloogle.org cloogle.org]: a search engine to search in Clean packages {{Programming languages}} [[Category:Functional languages]] [[Category:Term-rewriting programming languages]] [[Category:Free and open source compilers]] [[Category:Cross-platform free software]] [[Category:Programming languages created in 1987]] [[Category:Statically typed programming languages]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation needed
(
edit
)
Template:Cite FTP
(
edit
)
Template:Cite book
(
edit
)
Template:Cite thesis
(
edit
)
Template:Cite web
(
edit
)
Template:Date table sorting
(
edit
)
Template:Infobox programming language
(
edit
)
Template:No
(
edit
)
Template:Programming languages
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Use dmy dates
(
edit
)
Template:Yes
(
edit
)