Whisker Programming Language

A plain-spoken language that builds native binaries

Whisker reads like Go: let, fn, if and for, sized integers that wrap around, and .wsk files that compile to native binaries.

hello.wsk
type User struct {
  name string
  age  int
}

fn greet(u User) string { "Hello, " + u.name + "!" }

let hoge = User("Hoge", 3)
print(greet(hoge))
$ whisker run hello.wsk
Hello, Hoge!

What is Whisker?

Whisker is a functional programming language that reads the way a Go or Rust programmer expects: eleven reserved words, fn for every function and type for every type declaration. It has a gradual type checker, structs, sum types and interfaces, and integers of every size Go has: int8 to int64, uint8 to uint64, byte, rune and float32. A .wsk file transpiles to Go and builds into a single native binary.

Why Whisker?

📝

Plain, familiar syntax

Eleven reserved words: let, fn, return, if, else, for, break, continue, match, type, import. If you know Go, you can read it.

🔢

Sized integers

uint8, int32, uint64 and the rest behave as they do in Go: arithmetic wraps around, conversions keep the low bits, and two different sizes never meet without a conversion.

⚡

Native binaries

whisker build transpiles to Go and compiles with the Go toolchain. whisker transpile shows you exactly what Go it wrote.

🛠

Functional at heart

Lambdas with fn(x) { x * 2 }, partial application, map, filter, reduce, and the pipe |> to chain them.

🧩

Types that fit together

Structs, sum types, interfaces and methods, with match to take a value apart. Annotations are optional where they can be inferred.

🧪

Tools included

whisker test, whisker fmt and whisker lint come with the compiler. A function can state its contract with requires and ensures, and whisker verify proves it with z3. import go "path" reaches any Go package.

See it in action

fizzbuzz.wsk
fn fizzbuzz(n int) string {
  if n % 15 == 0 {
    return "FizzBuzz"
  } else if n % 3 == 0 {
    return "Fizz"
  } else if n % 5 == 0 {
    return "Buzz"
  }
  return string(n)
}

for i in 1..15 {
  print(fizzbuzz(i))
}
integers.wsk
// Sized integers wrap around, as they do in Go
let x uint8 = 255
print(x + 1)        // 0

let y int8 = 127
print(y + 1)        // -128

// A conversion keeps the low bits
let big = 300
print(uint8(big))   // 44

// Division by zero is an error you can catch
let z uint = 0
print(recover(1 / z, 0))   // 0
methods.wsk
type Showable interface {
  show() string
}

type User struct { name string, age int }

fn (u User) show() string { u.name + " (age " + string(u.age) + ")" }

type Shape struct {
  Circle(radius float)
  Rect(w float, h float)
}

fn area(s Shape) float {
  return match s {
    Circle(r) => 3.14 * r * r,
    Rect(w, h) => w * h
  }
}

print(User("Piyo", 5).show())
print(area(Rect(3.0, 4.0)))
pipeline.wsk
let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

// Keep the evens, square them, add them up
let total = nums
  |> filter(fn(x) { x % 2 == 0 })
  |> map(fn(x) { x * x })
  |> reduce(0, fn(acc, x) { acc + x })

print(total)   // 220
errors.wsk
fn divide(a int, b int) int {
  if b == 0 {
    fail("division by zero")
  }
  return a / b
}

print(recover(divide(10, 2), 0))    // 5
print(recover(divide(10, 0), 0))    // 0
print(divide(10, 0) |> recover(-1)) // -1

let handled = recover(divide(1, 0), fn(err error) {
  print("caught:", err)
  -1
})
print(handled)
contracts.wsk
// Contracts: what a function needs (requires) and what it promises (ensures).
// Inside an ensures, result is the value the function returns.
pure fn clamp(x int, lo int, hi int) int
  requires lo <= hi
  ensures result >= lo
  ensures result <= hi
{
  if x < lo { return lo }
  if x > hi { return hi }
  return x
}

print(clamp(15, 0, 10))
print(clamp(-3, 0, 10))

// Every clause is checked each time the function runs. A broken requires is
// an error, so recover catches it.
print(recover(clamp(1, 5, 2), "caught: lo is above hi"))

// A broken ensures is one too: this function does not keep its promise.
pure fn abs(x int) int
  ensures result >= 0
{
  return x
}

print(recover(abs(-3), fn(err error) { err }))

Frequently Asked Questions

What is the Whisker programming language?

Whisker is a plain-spoken programming language with Go-like syntax. Its source files use the .wsk extension. The whisker command transpiles them to Go and builds a native binary with the Go toolchain.

What file extension does Whisker use?

Whisker source files use the .wsk extension and are encoded in UTF-8. Tests live in files ending in _test.wsk and run with whisker test.

How do I install Whisker?

With Homebrew, run brew install 135yshr/tap/whisker. With Go 1.27 or later, go install github.com/135yshr/meow/cmd/whisker@latest also works, and every release on GitHub has archives for macOS, Linux and Windows. Building a program needs the Go toolchain.

Can Whisker check that a function keeps its promise?

Yes. A function can state what it needs with requires and what it promises with ensures, and the clauses are checked each time it runs. whisker test also tries the contract of each pure function on generated inputs, and whisker verify asks the z3 solver whether any input breaks it. whisker export lean writes the function and its contract as Lean 4 for a proof by hand.

Where can I try Whisker online?

The Playground at https://whisker.oreha.dev/playground/ runs Whisker in your browser through a WebAssembly build of the compiler's interpreter.

Get started in seconds

1

Install

brew install 135yshr/tap/whisker
2

Write

echo 'print("Hello, World!")' > hello.wsk
3

Run

whisker run hello.wsk