Draft:Coalton (programming language)
![]() | Draft article not currently submitted for review.
This is a draft Articles for creation (AfC) submission. It is not currently pending review. While there are no deadlines, abandoned drafts may be deleted after six months. To edit the draft click on the "Edit" tab at the top of the window. To be accepted, a draft should:
It is strongly discouraged to write about yourself, your business or employer. If you do so, you must declare it. Where to get help
How to improve a draft
You can also browse Wikipedia:Featured articles and Wikipedia:Good articles to find examples of Wikipedia's best writing on topics similar to your proposed article. Improving your odds of a speedy review To improve your odds of a faster review, tag your draft with relevant WikiProject tags using the button below. This will let reviewers know a new draft has been submitted in their area of interest. For instance, if you wrote about a female astronomer, you would want to add the Biography, Astronomy, and Women scientists tags. Editor resources
Last edited by Stylewiki (talk | contribs) 3 days ago. (Update) |
Comment: In accordance with Wikipedia's Conflict of interest policy, I disclose that I have a conflict of interest regarding the subject of this article. Stylewiki (talk) 22:29, 16 July 2025 (UTC)
Coalton | |
---|---|
![]() | |
Paradigms | multi-paradigm: functional, imperative |
Family | ML, Lisp |
Designed by | Robert Smith |
Developer | Robert Smith, Coalton community |
First appeared | 2018 |
Typing discipline | inferred, static, strong |
Platform | Common Lisp |
OS | Cross-platform |
License | MIT License |
Filename extensions | .lisp, .coal |
Website | coalton-lang |
Influenced by | |
Common Lisp, Scheme, Haskell, OCaml, Standard ML, Clojure, Rust |
Coalton is a functional, statically typed, general-purpose programming language embedded in Common Lisp. Its type system is similar to Haskell's, but evaluation is strict like Standard ML or OCaml. Metaprogramming is supported through traditional Lisp macros. Coalton focuses on performance through efficient data representation and compiler optimization[1].
Coalton refers to both the language and its implementation, and remains under active, open-source development as of July 2025[2].
History
Robert Smith started designing Coalton in 2018[3] to import the benefits of ML-like static typing into the interactive, incremental programming environment of Common Lisp. Coalton was further developed by a team led by Smith and was officially announced in 2021[4]. Coalton has since been used for quantum computing research, the implementation of the Quil compiler[5], and defense applications.
Coalton is used[6] at HRL Laboratories for building software for qubits based on exchange-only silicon dots.
Features
- Static typing with global type inference and optional type declarations.
- Parametric algebraic data types, pattern matching, and compile-time exhaustiveness checking.
- Multi-parameter type classes with functional dependencies.
- Strictly evaluated with lazy iterators.
- Advanced immutable data structures including hash array mapped tries and relaxed radix balanced trees.
- Machine code compilation (on Lisp hosts that support it).
- Compiler optimizations including heuristic inlining and user-controlled inlining with the
inline
directive. - User-controllable function monomorphization with the
monomorphize
directive. - User-controller data type representation control with the
repr
directive. - Separate development and release modes. Release mode enables greater compiler optimization opportunities at the expense of development interactivity.
- Non-allocating
Optional
data type (cf. Haskell'sMaybe
or OCaml'sOption
). - Exception handling with resumptions.
- Inline Common Lisp code with the
lisp
operator. - Metaprogramming via ordinary
defmacro
. - Advanced numerical data types including dual numbers, hyper-dual numbers, computable real numbers, and arbitrary-precision floating-point numbers.
Examples
When Coalton is written in a Lisp file, the Coalton code is wrapped in coalton-toplevel
:
(coalton-toplevel
;; ...definition forms...
)
In the following examples, we elide the coalton-toplevel
form.
Expressions are written in Lisp's prefix style:
(define pi-approx (/ 355.0 113.0))
(define earth-diameter-km 12756.0)
(define earth-circumference-km (* pi-approx earth-diameter-km))
Functions are defined with define
:
(define (square-area width height)
(* width height))
Algebraic data types are defined with define-type
and can be pattern matched:
(define-type (Shape :t)
(Rect :t :t) ; width x height
(Circle :t)) ; radius
(define (area s)
(match s
((Rect width height) (* width height))
((Circle radius) (* coalton-library/math:pi (^ radius 2)))))
The type of area
is automatically inferred as (Num :t) (Trigonometric :t) ⇒ (Shape :t → :t)
, which means that areas can be computed on shapes whose dimensions are specified to be numerical and trigonometric.
Type classes can be defined with define-type
. A mathematical Group
type class may be written like:
(define-class (Group :t)
(identity-element (:t))
(invert-element (:t -> :t))
(group-operation (:t -> :t -> :t)))
We may then define the additive group of integers by defining an instance of the type class on Integer
:
(define-instance (Group Integer)
(define identity-element 0)
(define (invert-element x)
(negate x))
(define (group-operation x y)
(+ x y)))
Saving an executable is done via the host Lisp compiler. A "Hello World" executable can be made by creating a file hello.lisp
:
(coalton-toplevel
(define (main)
(trace "Hello, world!")))
With a Common Lisp compiler like SBCL, an executable called hello
can be produced with:
sbcl --eval '(asdf:load-system "coalton")' \
--load hello.lisp \
--eval '(sb-ext:save-lisp-and-die "hello"
:executable t
:toplevel (lambda () (coalton:coalton (coalton-user::main))))' \
--quit
Running the executable produces the expected output:
% ./hello
Hello, world!
References
- ^ https://www.youtube.com/watch?v=of92m4XNgrM
- ^ https://github.com/coalton-lang/coalton
- ^ https://github.com/stylewarning/deprecated-coalton-prototype/blob/master/thoughts.md
- ^ https://coalton-lang.github.io/20211010-introducing-coalton/
- ^ https://coalton-lang.github.io/20220906-quantum-compiler/
- ^ https://meetings.aps.org/Meeting/MAR23/Session/F70.8
- Draft AfC submissions
- High-level programming languages
- Cross-platform free software
- Extensible syntax programming languages
- Functional languages
- Pattern matching programming languages
- Programming languages
- Programming languages created in 2018
- Statically typed programming languages
- ML programming language family
- Lisp programming language family