Skip to content

ghūl programming language

ghūl (pronounced 'ghoul') is a statically typed programming language for .NET 10. The compiler is about 120,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")
<<image tree.png>>
tree.png
tree.png

where to go next

  • Rosetta Code - 703 tasks solved in ghūl, 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.
  • getting started - ghūl on your own machine. A ghūl repository pins the compiler as a local .NET tool, so the compiler arrives with the code.

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 narrowing survives the calls the compiler can show leave it alone.

  • 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 at the end of a line.

The rest is what you would expect of a .NET language: classes, structs, traits and generics, first-class functions and closures, generators, async/await, and every NuGet package. ghūl produces ordinary assemblies and packages, and other .NET languages can call them.

The language is under active development: whatever the compiler accepts is the definitive reference.