Clean Language

Website Developer
7 min readJun 29, 2021

--

Today, the modern world we live in must be done by technology because it has a lot of advantages, more than physical work or mental thinking. The computer plays a big role in supporting our daily life because of its accuracy, fast and reliability — many tasks can be done simultaneously with a computer. Computers do not just work by themselves, and so programming language had been invented to let the developers can build up software, and operating system will be able to use to control it, telling it what to do. Many different modern programming languages are using widely today, Python, Java, C++, C#, HTML. But let us go back to when these languages did not exist yet. We are talking about “Clean,” a programming language invented in the 80s.

https://en.wikipedia.org/wiki/Clean_(programming_language)

Overview of Clean

Clean, a programming language, first appeared in 1987 by the Software Technology Research Group of Radboud University Nijmegen, one of the early languages that are still being further developed until today. Back in the day when first being developed history, Clean was being called “Concurrent Clean, in a collection of open-content textbooks Concurrent Clean — Wikibooks “Concurrent implies Clean can run the same process on several computers, but the word “Concurrent” was dropped at some point. The latest stable version, Clean 3.0 2 years ago in 2018, works on a cross-platform like Solaris, Apple Macintosh, and popular OS like Microsoft Windows, Linux.

Clean is a general-purpose programming language used in mathematics and science. It is a programming language general pure, lazy functional making real-world application and useful for writing bug-free or easy to debug programs in fewer line codes, formally providing properties of the programs, and directly offering what needs to be done for debugging. Some of its main features applied are unique typing, dynamic typing, and generic functions.

The purpose of clean is to create a software developer language to serve fast, non-strict that is easier to optimize. Being pure lazy functional characteristic, it prefers that only argument that needs to be evaluated in a function needs to be evaluated. Also, cleans functions are using partially strict evaluation when needed, which means that it can be easily optimized quicker and more efficiently than another programming language like Haskell — a programming language announced in 1990. It is explaining that Clean code, when writing, gives more information to the compiler than Haskell code. The nature of this language is somewhat different than the character of C, C++, and Java. You might not be familiar with it for the first time, but do not take it as an obstacle to learn it. It is much easier to learn functional programming in Clean than to become an equally qualified programmer in C++ or Java.

Basic looks

Talking about the feature of clean but before we dive into an individual feature, let us see examples of Clean to get the idea of how Clean are written to understand the concept of the language, also telling the difference from the modern programming language.

Start:: String

Start = “Hello world.”

Unlike other languages we are using today, the famous string Hello World is written differently, starting with “Start” instead of directly using “print” like other languages to write a String. At the start of this example, writes 720 to the console, the value of an expression is shown for the user, so the String “Hello World” is written like this.

fac :: Int ­> Int

fac 0 = 1

fac n = n * fac (n­1)

Start :: Int

Start = fac 6

In this example, in the first line, it says the functions int as input also int as an output, saying that the function is taking a number as a parameter and returning an integer. Line 2,3 are arguments following the rules of the functions. In line 4, Start will compute the values of input and evaluate fac 6. Here we can overlook how to clean basics can be written and how a function in Clean would work.

Looping in Clean

module StringConcatenation

import StdEnv

import ArgEnv

loop :: !Int *String -> *String

loop 0 s = s

loop i s = loop (i-1) (s +++. “hello\n”)

Start = toString (size s) +++ “\n”

where

s = loop n “”

n = toInt (select getCommandLine 1)

Generally, looping in Clean looks a lot like modern programming language and about how it would function like others except in Clean if a user is writing a loop statement. A loop in a computer program is an instruction that repeats until a specified condition is reached. In a loop structure, the loop asks a question. If the answer requires action, it is executed. The same question is asked again and again until no further action is required.

Strongly Type

Clean is a strongly typed language based on an extension of the well-known Milner/Hindley/Mycroft type inferencing/checking scheme and the common higher-older types, polymorphic types, abstract types, algebraic types, type synonyms, and existentially quantified types. Because of having various typing types built-in, Clean can generate limited and less error in the number of programs. It is also included a dynamic type that allows values of arbitrary types to be wrapped in a uniform package and unwrapped through a type of annotation at run time. Dynamic type in Clean also helps code and data can be exchanged between Clean applications flexibly and safely.

Lazy, pure, and higher-order functional

As known as a lazy programming language. Clean offers only if an expression is evaluated if it is used in a program. It also means that explicit graph rewriting semantics in Clean. And another function is that Clean uses techniques of a rewrite, create a new graph of the original one algorithmically. Talking about higher-order functional in clean is a function that takes it as an argument then returns a function. Higher-order function contrasts with first-order functions, which do not take a function as an argument or return a function as output.

Libraries

Clean IDE has many libraries available to offer any additional functionality though they are not yet completed and may contain errors. This means that the user must manually go over the code and debug them. Some of the libraries are “StdEnv,” a Clean standard library, “WrapDebug” Debugging tool utilities, “ExtendedArith” Big integers, rational, and complex numbers.

Predefined and user-defined types.

Clean offers various predefined types: integers, reals, Booleans, characters, strings, lists, tuples, records, arrays, and files. These types are commonly seen in many modern programming languages, but it has its unique types. In Clean, type ‘Real’ is used for 64-bit double-precision floating-point values. We list some an example in Clean to see some peculiarities of the language.

1. [1, 3…9]

2. [1.9]

3. [1,2,3,4,5]

As we can see from the above examples, the syntax of using a list is quite straightforward. In Clean, there is ‘dot’ (‘..’) syntax facilitating the definition of successive values. A tuple is an algebraic data type predefined for reasons of programming convenience and efficiency. Tuples have an advantage in that they allow bundling a finite number of objects of arbitrary type into a new object without being forced to define a new algebraic type for such a new object. This is handy for functions that return several values. In Clean, the programmer can define algebraic types, record types, and synonyms.

Classes and overloading

Clean has a compelling notion of classes. It is important to understand that this class concept is different from the classes you might know from object-oriented languages. In Clean, a class is a family of functions with the same name. The difference between these family members is the type processed. As a straightforward example, consider the class of increment functions.

class inc t :: t ­> t

Modularity and sophisticated I/O.

The module structure is used to control the scope of definitions. The basic idea is that definitions only have a meaning in the implementation module they are defined in unless the corresponding definition module exports them. Having the exported definitions collected in a separate definition module has as advantage that obtains a self-contained interface document, one can reach out to others. The definition module is a document that defines which functions and data types can be used by others without revealing uninteresting implementation details. Furthermore, the module structure enables separate compilation that heavily reduces compilation time. If the definition module stays the same, a change in an implementation module only will cause the recompilation of that implementation module. When the definition module is changed, only those implementation modules affected by this change need to be recompiled.

Clean also offers a sophisticated I/O library with which GUI applications can be built easily. The portability of the Clean program makes it possible to use the same source code without any modification.

Takeaway

Clean is programming that was developed long ago in the 80s — it a similar syntax to Haskell, which came out a couple of years after. If anyone has experience with either one also being said one “Clean” website, it is an impression of an easier programming language to learn than any others today. Take Java, HTML, for example. They are widely used for websites and mobile applications even though harder to learn compared to Clean. Clean was a closed source, offering only commercial licenses. A few years ago, Clean was released as open-source under LGPL.

Clean is not community-focused. It is not clear for outsiders how to contribute to the language/compiler. There is no package management, so there is no way to let the community contribute to libraries effectively. Documentation is there but only maintained by the “Clean” group. You would have to use the mailing list to share or ask for information. This makes it hard for an outsider to get started on Clean for anything ‘productive in the real world’. By that, I mean that you usually need many libraries to get productive. Libraries are not easy to find, and they’re probably is no documentation for them. Perhaps if it is simply easier to learn, it may be why it is not popular to use for coders and companies.

--

--

Website Developer
Website Developer

No responses yet