Created
July 15, 2024 06:03
-
-
Save ymdryo/972a6666f1e9dc969a8da62ec6cd3797 to your computer and use it in GitHub Desktop.
Elaine semantics test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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