koka-logo

Koka
A Functional Language with Effect Types and Handlers

// A generator effect with one operation
effect yield<a> {
  fun yield( x : a ) : ()
}

// Traverse a list and yield the elements
fun traverse( xs : list<int> ) : yield<int> () {
  match(xs) {
    Cons(x,xx) -> { yield(x); traverse(xx) }
    Nil        -> ()
  }
}

fun main() : console () {
  with fun yield(i : int) {
    println("yielded " ++ i.show)    
  }
  [1,2,3].traverse
}
// A generator effect with one operation
effect yieldindex/yield: V -> HX<aa: V> {
  fun yieldindex/yield: forall<a> (x : a) -> (yield<a>) ()( xx: $132 : aa: V ) : (std/core/types/(): V)std/core/types/(): V
}

// Traverse a list and yield the elements
fun traverseindex/traverse: (xs : list<int>) -> (yield<int>) ()( xsxs: list<int> : liststd/core/list: V -> V<intstd/core/types/int: V> ) : yieldindex/yield: V -> HX<intstd/core/types/int: V> (std/core/types/(): V)std/core/types/(): V {
  match(xsxs: list<int>) {
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: int,xxxx: list<int>) -> { yieldindex/yield: forall<a> (x : a) -> (yield<a>) ()(xx: int); traverseindex/traverse: (xs : list<int>) -> (yield<int>) ()(xxxx: list<int>) }
    Nilstd/core/Nil: forall<a> list<a>        -> (std/core/types/(): ())std/core/types/(): ()
  }
}

fun mainindex/main: () -> console ()() : consolestd/core/console: X (std/core/types/(): V)std/core/types/(): V {
  withhandler: (() -> <yield<int>,console> ()) -> console () fun yieldyield: (i : int) -> console ()(ii: int : intstd/core/types/int: V) {
    printlnstd/core/println: (s : string) -> console ()("yielded " ++std/core/(++).1: (x : string, y : string) -> string ii: int.showstd/core/show: (i : int) -> string)    
  }
  [std/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>1,2,3]std/core/Nil: forall<a> list<a>.traverseindex/traverse: (xs : list<int>) -> (yield<int>) ()
}

Welcome to Koka – a strongly typed functional-style language with effect types and handlers.

Install Get Started Documentation Github

Note: Koka v2 is a research language that is currently under development and not ready for production use. Nevertheless, the language is stable and the compiler implements the full specification. The main things lacking at the moment are libraries, package management, and deep IDE integration.

News:

  • 2021-06-23: Koka v2.1.9 released, initial cross-module specialization (by Steven Fontanella)
  • 2021-06-17: Koka v2.1.8 released, initial Apple M1 support.
  • The Perceus paper won a distinguished paper award at PLDI'21!
  • 2021-06-10: Koka v2.1.6 released.
  • 2021-05-31: Koka v2.1.4 released.
  • 2021-05-01: Koka v2.1.2 released.
  • 2021-03-08: Koka v2.1.1 released.
  • 2021-02-14: Koka v2.0.16 released.
  • 2020-12-12: Koka v2.0.14 released.
  • 2020-12-02: Koka v2.0.12 released.
  • 2020-11-29: Perceus technical report publised (pdf).

Why Koka?

Install

For Linux (x64, arm64) and macOS (x64, M1), you can install Koka using:

curl -sSL https://github.com/koka-lang/koka/releases/latest/download/install.sh | sh

For Windows (x64), open a cmd prompt and use:

curl -sSL -o %tmp%\install-koka.bat https://github.com/koka-lang/koka/releases/latest/download/install.bat && %tmp%\install-koka.bat

This also installs syntax highlighting for the VS Code and Atom editors.

After installation, verify if Koka installed correctly:

$ koka
 _         _
| |       | |
| | _ ___ | | _ __ _
| |/ / _ \| |/ / _' |  welcome to the koka interactive compiler
|   ( (_) |   ( (_| |  version 2.1.7, Jun 15 2021, libc x64 (gcc)
|_|\_\___/|_|\_\__,_|  type :? for help, and :q to quit

loading: std/core
loading: std/core/types
loading: std/core/hnd
> 

Type :q to exit the interactive environment.

For detailed installation instructions and other platforms see the releases page. It is also straightforward to build the compiler from source.

Get started with the compiler