Koka language preview
1. Effects and handlers
an effect declaration, an effect type, and a handler
horizon-dark
// prints a greeting with an effect
effect ctl ask() : int
fun greet() : <ask,console> ()
val name = ask()
println("Hello, " ++ name.show)
fun main()
handle(greet)
ctl ask() -> resume(42)
atom-one-dark
// prints a greeting with an effect
effect ctl ask() : int
fun greet() : <ask,console> ()
val name = ask()
println("Hello, " ++ name.show)
fun main()
handle(greet)
ctl ask() -> resume(42)
github-dark
// prints a greeting with an effect
effect ctl ask() : int
fun greet() : <ask,console> ()
val name = ask()
println("Hello, " ++ name.show)
fun main()
handle(greet)
ctl ask() -> resume(42)
dracula
// prints a greeting with an effect
effect ctl ask() : int
fun greet() : <ask,console> ()
val name = ask()
println("Hello, " ++ name.show)
fun main()
handle(greet)
ctl ask() -> resume(42)
nord
// prints a greeting with an effect
effect ctl ask() : int
fun greet() : <ask,console> ()
val name = ask()
println("Hello, " ++ name.show)
fun main()
handle(greet)
ctl ask() -> resume(42)
github
// prints a greeting with an effect
effect ctl ask() : int
fun greet() : <ask,console> ()
val name = ask()
println("Hello, " ++ name.show)
fun main()
handle(greet)
ctl ask() -> resume(42)
2. Pattern matching
match with the Just/Nothing literals
horizon-dark
fun describe(x : maybe<int>) : string
match x
Just(n) -> "got " ++ n.show
Nothing -> "nothing" atom-one-dark
fun describe(x : maybe<int>) : string
match x
Just(n) -> "got " ++ n.show
Nothing -> "nothing" github-dark
fun describe(x : maybe<int>) : string
match x
Just(n) -> "got " ++ n.show
Nothing -> "nothing" dracula
fun describe(x : maybe<int>) : string
match x
Just(n) -> "got " ++ n.show
Nothing -> "nothing" nord
fun describe(x : maybe<int>) : string
match x
Just(n) -> "got " ++ n.show
Nothing -> "nothing" github
fun describe(x : maybe<int>) : string
match x
Just(n) -> "got " ++ n.show
Nothing -> "nothing" 3. Trailing lambdas
a function passed as a trailing block
horizon-dark
fun main()
[1, 2, 3].map fn(x)
x * 2 atom-one-dark
fun main()
[1, 2, 3].map fn(x)
x * 2 github-dark
fun main()
[1, 2, 3].map fn(x)
x * 2 dracula
fun main()
[1, 2, 3].map fn(x)
x * 2 nord
fun main()
[1, 2, 3].map fn(x)
x * 2 github
fun main()
[1, 2, 3].map fn(x)
x * 2