Kokaの例: Generator
code:koka(js)
effect yield<a>
fun yield(x: a): ()
fun traverse(xs: list<a>): yield<a> ()
match xs
Cons(x,xx) -> { yield(x); traverse(xx) }
Nil -> ()
handle部分
code:koka(js)
fun main(): console ()
with fun yield(i: int)
println("yielded " ++ i.show)
1,2,3,4,5.traverse
with fun ..を使うことで自然にresumeしてる
ref Kokaのoperation keywords
code:result
yielded 1
yielded 2
yielded 3
yielded 4
yielded 5
参考
koka/yield.kk at b1670308f88dd1fc6c22cad28385fcb185d5b27d · koka-lang/koka · GitHub
恐らく古いverionのKokaで書かれてる
@yurihaia: kinda cool research language named Koka
the concepts (especially effects & effect handlers) allows making your own generators, async-await, and stuff like that all
https://pbs.twimg.com/media/E0SB801XEAAZn1b.pnghttps://pbs.twimg.com/media/E0SB9-zXMAUlYdF.png