ghūl programming language

ghūl (pronounced 'ghoul') is a statically typed programming language with three targets: .NET 10, WebAssembly and native executables through LLVM. The compiler is about 200,000 lines of ghūl, and compiles itself.
Every example on this site is a whole program. Press edit & run, change it, and run it in your browser.
choosing a target
The .NET target is the full one. A ghūl project is an ordinary .NET SDK project, ghūl code can use any .NET library and NuGet package, and other .NET languages can call it. Use it for a real project today.
The ghul command builds the WebAssembly and native targets and doesn't need the .NET SDK. It installs without .NET on Linux, x64 and arm64. A WebAssembly program runs under Node.js, or in a browser that supports WasmGC, which is how the examples on this site run. A native program is a single statically linked executable for Linux on x64 or arm64.
| .NET | WebAssembly | native | |
|---|---|---|---|
| build with | dotnet build | ghul build | ghul build |
| runs on | the .NET 10 runtime | Node.js, or a browser | Linux x64 and arm64 |
| libraries | all of .NET and NuGet | ghūl's own libraries | ghūl's own libraries |
| calls into | any .NET API | functions the loading script supplies, with @extern | C, with @extern |
WebAssembly and native programs use ghūl's own libraries, ghul-core and ghul-runtime, about 22,000 lines of ghūl, in place of .NET's. They build the compiler and run most of the Rosetta Code solutions on this site. They don't include regular expressions, HTTP, sockets or culture-aware formatting, decimal isn't supported on either, and a program can't call a library that already exists. A WebAssembly program calls JavaScript through its @extern declarations, and the functions available are the ones the script that loads it supplies. WebAssembly and native executables list what each target supports, and .NET integration lists what only .NET provides.
where to go next
- Rosetta Code - over a thousand tasks solved in ghūl, from one-liners to graphics and games, searchable and nearly all runnable here. The page opens on one picked at random.
- the tour - the language a topic at a time, every example editable.
- the online REPL - type ghūl a submission at a time and see each result, in your browser.
- scripts, the REPL and notebooks - run a
.ghulfile directly, or type ghūl into an interactive session or a notebook. No project needed. - getting started - ghūl on your own machine, with the .NET SDK or with the
ghulcommand alone.
what is distinctive
type narrowing - a value's type follows control flow. A null test, an
isa, a union variant test or anif letnarrows whatever was tested - a local, a field, or a whole member-access path - and the compiler keeps the narrowed type across any call it can show leaves the tested value unchanged.everything is an expression -
if,case, loops and blocks all yield values. Aforloop that finds something evaluates to what it found.unions and pattern matching - refutable patterns match by type and by value, and a
caseover a closed domain - a union, an enum,bool, a closed class hierarchy, a tuple of those - is checked for coverage.keywords, not braces - blocks open with a keyword and close with its mirror:
is...si,if...fi,do...od. No semicolons, except to put two statements on one line.
The rest is what you would expect of a statically typed language: classes, structs, traits and generics, first-class functions and closures, generators and async/await. On .NET, ghūl produces ordinary assemblies and NuGet packages, and other .NET languages can call them.
The language is under active development: whatever the compiler accepts is the definitive reference.