ArticleslgStudy

mathematics

Clean (programming language)

Clean (programming language) is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Clean (programming language) rather than just read about it. In short: Clean is a general-purpose purely functional programming language. Originally called the Concurrent Clean System or the Clean System, it has been developed by a group of researchers from the Radboud University in Nijmegen since 1987.

Clean (programming language) — main illustration
Clean (programming language) — illustration

Key takeaways

  • Clean (programming language) belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Clean (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Clean (programming language) from memory before moving on to harder problems.

Reference excerpt

Clean is a general-purpose purely functional programming language. Originally called the Concurrent Clean System or the Clean System, it has been developed by a group of researchers from the Radboud University in Nijmegen since 1987. Although development of the language has slowed, some researchers are still working in the language. In 2018, a spin-off company was founded that uses Clean.

Features 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. An integrated development environment (IDE) for Microsoft Windows is included in the Clean distribution. An extension for Visual Studio Code also exists that integrates with Eastwood, the language server for Clean.

Examples Hello world:

Factorial:

Fibonacci sequence:

Infix operator:

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.

How Clean works 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. A 2008 benchmark showed that Clean native code performs similarly to the Glasgow Haskell Compiler (GHC), depending on the benchmark.

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. Intermediate ABC code is converted to object code (.o) by the code generator written in 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 (when available) or a dedicated linker written in Clean on Windows. Earlier versions of the Clean compiler were written completely in 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 abstract graph rewriting machine. 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 Start 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 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.

Platforms 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:

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:

References

External links Clean Wiki clean-lang.org: public registry with Clean packages cloogle.org: a search engine to search in Clean packages

Worked examples

Example 1 — a first encounter with Clean (programming language)

Start with the simplest possible case. Write down what Clean (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Clean (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Clean (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Clean (programming language)

In research
Clean (programming language) appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Clean (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Clean (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Cross-platform free software, Free and open source compilers, Functional languages, so understanding it makes those chapters shorter.
In everyday life
Look for Clean (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Clean (programming language)” →

How to study Clean (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Clean (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Clean (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Clean (programming language) in simple terms?

Clean is a general-purpose purely functional programming language. Originally called the Concurrent Clean System or the Clean System, it has been developed by a group of researchers from the Radboud University in Nijmegen since 1987.

Why does Clean (programming language) matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Clean (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Clean (programming language).

Tags

  • Cross-platform free software
  • Free and open source compilers
  • Functional languages
  • Programming languages created in 1987
  • Statically typed programming languages
  • Term-rewriting programming languages

Keep exploring