This repository is the home of the Coal programming language and compiler.
Coal is a declarative, statically typed, purely functional programming language with simple and intuitive syntax. It provides algebraic data types and pattern matching, extensible records, structural recursion, codata, and traits (type classes), among other features. Coal’s type system, like Haskell’s and ML’s, supports type inference and parametric polymorphism, drawing on the System-F lambda calculus. The Coal compiler is implemented in Haskell and targets LLVM for code generation. As a total language, Coal takes a different approach to recursion, following the motto that "recursion is the goto of functional programming." To guarantee that programs are provably terminating, recursion is only available in a restricted form, known as structural recursion. The language finds inspiration in ideas from the field of Mathematics of Program Construction, where streams and other infinite data types are described as coalgebras — hence the name Coal.
The language documentation is available at: coal-lang.org
For instructions on how to use Coal in a Docker-based workflow, please see this page.
The compiler currently works on Linux and Mac OS. Windows support is not yet available.
A recent version of GHC is needed. It is recommended to install Haskell, GHC and Stack using the GHCup tool.
An LLVM toolchain that provides llvm-as and llc (the LLVM static compiler) is also required.
-
Debian/Ubuntu (or derivatives):
sudo apt update sudo apt install llvm clang -
Fedora, RHEL, or CentOS:
sudo dnf install llvm clang -
Arch Linux:
sudo pacman -S llvm
See Getting Started with the LLVM System, or install using Homebrew:
brew install llvm
Note: If you use Homebrew to install LLVM, you may need to add the binaries to your PATH manually.
- GCC (probably not needed on Mac)
- Boehm–Demers–Weiser garbage collector
- The GNU Multiple Precision Arithmetic Library
-
Debian/Ubuntu (or derivatives):
sudo apt update sudo apt install libgc-dev libgmp-dev build-essential -
Fedora, RHEL, or CentOS:
sudo dnf install gc-devel gmp-devel gcc make -
Arch Linux:
sudo pacman -S gc gmp base-devel
brew install bdw-gc gmp
Clone the repository:
git clone ssh://git@codeberg.org/laserpants/coal.git
cd coal && chmod +x project && ./project install
Restart or refresh your shell, using e.g., exec $SHELL -l. To verify that the executable is installed, run:
coal --version
module Main {
import IO(println_string)
fun main() =
println_string("Hello, world!")
}
Save this program as "Main.coal". Compile the program with the command:
coal compile -I. Main.coal -o dist
A project declares its dependencies in a coal.json manifest. Start a new project with coal init, then add packages:
coal add https://codeberg.org/laserpants/coal-containers.git
Each dependency is pinned by a SemVer constraint, e.g. "0.5.1" (exact), ">=0.5.0", or "*".
See the CLI reference section of the documentation for more details.
This is an open and evolving project — contributions are welcome. Please see CONTRIBUTING.md for details.
The documentation is built with Zensical. The source code is hosted at: github.com/laserpants/coal-docs.
This project is licensed under the terms of the MIT license. See the LICENSE file in this repository for details.
