Skip to content

Instantly share code, notes, and snippets.

@ezyang
Created June 20, 2021 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezyang/592626fd8f13383ded9cdaeeb8eb55fb to your computer and use it in GitHub Desktop.
Save ezyang/592626fd8f13383ded9cdaeeb8eb55fb to your computer and use it in GitHub Desktop.
ezyang-mbp:labs ezyang$ cat a.kk
fun reuse( g : list<int> -> int, x : list<int>) : (int, int) {
(match(x) {
Nil() -> 0
Cons(_, _) -> 1
}
, g(x))
}
ezyang-mbp:labs ezyang$ koka -O2 -l -c --showcore a.kk
compile: a.kk
loading: std/core
loading: std/core/types
loading: std/core/hnd
check : a
module a
private import std/core/types = std/core/types = "";
private import std/core = std/core = "";
public fun reuse : (g : (list<int>) -> int, x : list<int>) -> (int, int)
= fn(g: (list<int>) -> int, x: list<int>){
val .b.38.36 : int
= g((std/core/types/.dup(x)));
std/core/types/(,)((std/core/types/.box((match (x) {
(std/core/Nil() : (list<int>) )
-> 0;
(.skip std/core/Cons(((.skip std/core/types/.Box((.pat1: int)) : .Box ) as .box-x34: .Box), (.pat2: list<int>)) : list<int> )
-> std/core/types/.drop(x, (std/core/int32(2)));
1;
}))), (std/core/types/.box(.b.38.36)));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment