Skip to content

Instantly share code, notes, and snippets.

@ymdryo
Created July 15, 2024 06:03
Show Gist options
  • Save ymdryo/972a6666f1e9dc969a8da62ec6cd3797 to your computer and use it in GitHub Desktop.
Save ymdryo/972a6666f1e9dc969a8da62ec6cd3797 to your computer and use it in GitHub Desktop.
Elaine semantics test
use std;
effect State {
get() Int
put(Int) ()
}
let hState = handler {
return(x) {
fn(s: Int) {
x
}
}
get() {
fn(s: Int) {
let f = resume(s);
f(s)
}
}
put(n) {
fn(s: Int) {
let f = resume(());
f(n)
}
}
};
effect Scope! {
scope!(a) a
}
let eScope = elaboration Scope! -> <> {
scope!(a) { a }
};
let elab_then_handle =
handle[hState] {
elab[eScope] {
let n = scope!(get());
put(2);
let m = scope!(get());
(n,m)
}
};
let handle_then_elab =
elab[eScope] {
handle[hState] {
let n = scope!(get());
put(2);
let m = scope!(get());
(n,m)
}
};
let main = elab_then_handle(5); # ok: (5, 2)
# let main = handle_then_elab(5); # error on evaluation stage:
# elaine: could not reduce or decompose: Var (Ident {idText = "scope!", location = LocOffset 783})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment