Skip to content

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.

drawing: a fractal tree
ghul
use System.Math
use Raster.IMAGE
let spread = 0.4D
let shrink = 0.76D
let image = IMAGE(500, 500)
branch(
x: double, y: double,
angle: double, length: double,
depth: int
) is
if depth == 0 then
return
fi
let tip_x = x + length * Math.cos(angle)
let tip_y = y + length * Math.sin(angle)
image.stroke(0.6D * cast double(depth))
image.line(x, y, tip_x, tip_y)
branch(tip_x, tip_y, angle - spread, length * shrink, depth - 1)
branch(tip_x, tip_y, angle + spread, length * shrink, depth - 1)
si
image.view(0.0D, 0.0D, 500.0D, 500.0D)
image.colour(60ub, 40ub, 20ub)
branch(250.0D, 10.0D, Math.pi / 2.0D, 110.0D, 10)
image.write("tree.png")
image.show("tree.png")

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.

.NETWebAssemblynative
build withdotnet buildghul buildghul build
runs onthe .NET 10 runtimeNode.js, or a browserLinux x64 and arm64
librariesall of .NET and NuGetghūl's own librariesghūl's own libraries
calls intoany .NET APIfunctions the loading script supplies, with @externC, 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 .ghul file 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 ghul command alone.

what is distinctive ​

  • type narrowing - a value's type follows control flow. A null test, an isa, a union variant test or an if let narrows 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. A for loop that finds something evaluates to what it found.

  • unions and pattern matching - refutable patterns match by type and by value, and a case over 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.