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-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 and macOS on x86 64-bit, you can install Koka using:

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

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

> koka
 _          _           ____
| |        | |         |__  \
| | __ ___ | | __ __ _  __) |
| |/ // _ \| |/ // _' || ___/ welcome to the koka interpreter
|   <| (_) |   <| (_| ||____| version 2.0.10, Nov 28 2020, libc 64-bit (gcc)
|_|\_\\___/|_|\_\\__,_|       type :? for help

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

Type :q to exit the interpreter.

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

Running the compiler A tour of the Koka language