Languages

Aleph

A pure, lazy, strongly typed language and its native compiler: written in Aleph, emitting LLVM for nine targets, with its own runtime.

Released 0.2.62 (Windows and Linux installers)

Aleph

Aleph is MLambda’s general-purpose programming language, and every MLambda program is built with it: the compilers of the other languages, the actor runtime, the database, the services and the windows. It is pure, lazy and Hindley–Milner typed, shaped like Haskell and ML, with significant indentation, and it compiles to native code through LLVM. Its compiler is written in Aleph, and so is its standard library, from the heap up to TLS 1.3.

The language

data Shape = Circle { r :: Float } | Rect { w :: Float, h :: Float }

trait Area a where
  area :: a -> Float

instance Area Shape where
  area s = case s of
    Circle r -> 3.14159 * r * r
    Rect w h -> w * h

main :: Int
main = putStrLn (show (area (Rect 2.0 3.0)))
  • Values, not effects. Functions are pure and evaluation is lazy, with strictness analysis. A failure is a typed value (Either), not an exception. There is no null, and a case is checked for exhaustiveness.
  • Traits are interfaces, instances are classes. A data type holds a class’s fields, and its instance of a trait holds its methods. Code written against a trait (f :: Area a => a -> Float) works for every instance. Traits have associated types (type families), default methods and attributes, and existential constructors carry their dictionary.
  • Pattern matching everywhere. Constructors, literals, tuples, records, as-patterns and view patterns, nested, with a located error on a missed case.
  • Attributes are functions. @route("counter") above a binding applies the function route "counter" to it, the way a Python decorator does. The same attribute works on every target, so a library’s settings need no reflection.
  • Concurrency without locks. Fibers on an M:1 scheduler, CSP channels, select, futures and software-transactional memory (atomically, retry, orElse); multicore work fans out over processes or threads (System.Parallel, System.Threads).
  • Down to the machine. import "c" reaches a C function, import "asm" inline assembly, import "llvm" an intrinsic, import "ir" an LLVM IR body, import "wasm:web" a function of the page that hosts a WebAssembly build. A foreign module binds a whole library at once.

The compiler

The compiler (MLambda.Aleph, about 190 Aleph modules) is a pipeline of small phases. Each phase is a trait with its instances, and every decision it does not have to make in code is made by Shin rules.

 .ai source
   │  Front end      MLambda.Grammar.Aleph: lexer, off-side layout, parser and AST, generated by Church from
   │                 aleph.ebnf and aleph.asdl; the renamer (names, qualified methods, decorators) → Core IR
   ▼
 Core IR
   │  Types          Hindley–Milner inference with traits, associated types and a constraint solver;
   │                 unification, contexts, recursive types, per-site instantiation across modules
   │  Desugar        the pattern compiler (decision trees), dictionary passing, relations, intrinsics
   │  Optimise       beta and case reduction, inlining, dead-code elimination, dictionary specialisation,
   │                 defunctionalisation, tail-call contification and rewriting, thunk forcing, usage analysis
   │  Configuration  cfg gating on the target triple; the freestanding validator for bare-metal builds
   ▼
 LLVM IR
   │  Back end       ADT and C-struct layouts, tag and trait registries, closures, code per expression form
   │  Foundry        libLLVM: the target machine, the ORC JIT (aleph run), object files, the linker, the
   │                 shadow stack that gives the collector its roots, the partitioner for split builds
   ▼
 native executable · object · .wasm

The compiler decides nothing

Four theories in rules/ hold what a compiler usually hard-codes:

Theory What it derives
platforms.shin Each target’s runtime backend, linker, machine, ABI, relocation model, executable suffix and TLS stack. A triple no rule knows is refused by name.
pipeline.shin The stages of a run (build, Tsadi, test, Ayin) from the repository’s kind and its overrides.
packages.shin How a dependency is resolved and what a build reuses.
commands.shin Which command a verb runs, installed or offered by a project.

The compiler asserts what it read (the triple asked for, the manifest’s kind, the members) and reads the answers back. Adding a platform means adding facts, not editing a case.

Targets

Triple Where it runs
x86_64-pc-windows-msvc Windows
x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl Linux, dynamic or fully static (14 MB service images)
aarch64-unknown-linux-gnu ARM64 Linux
aarch64-linux-android31 Android
arm64-apple-macosx13.0.0 macOS
riscv64-unknown-linux-gnu, riscv64-unknown-elf RISC-V Linux, and bare metal for MLambda.OS
wasm64-unknown-unknown The browser, driven frame by frame by the page

Each platform’s runtime lives in its own folder, OS/<Os>/<Arch>/, as an instance of the runtime’s traits. There is no #ifdef in application code.

The runtime

The runtime is written in Aleph: the heap and its tracing collector (roots found on a shadow stack), strings and bytes, the fiber scheduler with epoll on Linux, STM and channels, signals, time, and the operating-system doors per platform. Programs start in about 0.2 seconds as native binaries.

The toolchain

One command does everything:

Command What it does
aleph new, aleph build, aleph run Make a project, build it natively, run it (JIT for development)
aleph check, aleph lint, aleph fmt Type-check, lint (dead code, unused bindings, non-exhaustive cases), format
aleph test Run the tests; --discover runs the scenes Tsadi derives, --verify runs Ayin’s judgement
aleph clean Refactor until Ayin is satisfied (Litush)
aleph doc, aleph lsp API documentation, the language server (VS Code and IntelliJ plug-ins)
aleph add, aleph update, aleph kleene Dependencies from git, locked by sha256; Kleene plans what a build takes from other repositories
--coverage, --profile-mem, --profile-cpu Coverage and profilers

A project is an aleph.toml. Its generators ([generate.<name>]) run other compilers before the build: Hilbert writes Aleph from .hb and .hs, Samek from .sk, Aphrodite from .ap, Dream from .dm, Max from .max. A generator is itself an Aleph project, built once and cached by the hash of its sources, and a step runs only when its inputs changed.

A build

The standard library

Written in Aleph, organised by what it is for:

  • Data and Control: lists, maps, sets, text and UTF-8, big integers, regular expressions, TOML, JSON, codecs, compression (deflate, inflate); functor, monad, foldable, lenses, logic, STM, async, channels, observables.
  • Crypto: SHA-2, HMAC, HKDF, ChaCha20-Poly1305, X25519, Ed25519, P-256 and ECDSA, RSA, X.509 and certificate paths, a DRBG, and a native TLS 1.3 where no OpenSSL may be linked.
  • System: files, processes, networking (TCP, UDP, DNS), an HTTP client and server with WebSockets, TLS, logs, Prometheus metrics, health, W3C trace context, signals and graceful shutdown.
  • Maths and media: a computer-algebra system (simplifier, differentiator, integrator, solver), proofs, image and video codecs (JPEG, PNG, WebP; H.264, VP8, VP9, MJPEG decoders).
  • GPU: the door to each system’s driver, used by Hilbert.Tensor and the window renderer.
  • Test: suites, assertions, properties and benchmarks.

Get it

Aleph is in the MLambda Store: a Windows setup and portable zip, a .deb for Ubuntu and Debian, and a Linux archive.

$ aleph --version
aleph 0.2.62
$ aleph new hello && cd hello && aleph run
Hello from Aleph
$ aleph test --verify
ayin: pass · 0 warnings