Skip to content

Commit 7eacd06

Browse files
committed
Add Koka example to prior art
The Koka language provides an interesting alternative data point for how generators and other powerful control flow constructs could work in a typed language such as Rust. Let's include an example in the prior art section. (Thanks to zesterer for asking for this.)
1 parent 31c7b28 commit 7eacd06

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

text/3513-gen-blocks.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,32 @@ main = putStrLn $ show $ take 5 $ oddDup [1..20]
556556
[clean-lang]: https://wiki.clean.cs.ru.nl/Clean
557557
[idris-lang]: https://www.idris-lang.org/
558558

559+
## Koka
560+
561+
The [Koka][] language, by contrast, does not lean on laziness. Instead, like Scheme, Koka provides powerful general control flow constructs from which generators, async, coroutines, and other such things fall out naturally. Unlike Scheme, these powerful control flow constructs are *typed* and are called effect handlers. E.g.:
562+
563+
```koka
564+
effect yield<a>
565+
fun yield(x : a) : ()
566+
567+
fun odd_dup(xs : list<int>) : yield<int> ()
568+
match xs
569+
Cons(x,xx) ->
570+
if x % 2 == 1 then
571+
yield(x * 2)
572+
odd_dup(xx)
573+
Nil -> ()
574+
575+
fun main() : console ()
576+
with fun yield(i : int)
577+
println(i.show)
578+
list(1,20).odd_dup
579+
```
580+
581+
Note that there is no library being used here and that `yield` is not a keyword or feature of the language. In Koka, the code above is all that is needed to express generators.
582+
583+
[koka]: https://koka-lang.github.io/
584+
559585
# Unresolved questions
560586
[unresolved-questions]: #unresolved-questions
561587

0 commit comments

Comments
 (0)