Created
April 11, 2020 16:07
-
-
Save philipschwarz/a1b5f3d7577489c6332b230aa7faae46 to your computer and use it in GitHub Desktop.
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 .base | |
use List Optional | |
List.head : [a] -> Optional a | |
List.head a = List.at 0 a | |
ability State s where | |
put : s -> {State s} () | |
get : {State s} s | |
pop : '{State [a]} (Optional a) | |
pop = ' let stack = get | |
put (drop 1 stack) | |
head stack | |
push : a -> {State [a]} () | |
push a = put (cons a get) | |
> .base.head [1,2,3] | |
state : s -> '({State s} a) -> a | |
state s c = | |
h s e = match e with | |
{ State.get -> k } -> | |
handle k s with h s | |
{ State.put s -> k } -> | |
handle k () with h s | |
{ a } -> a | |
handle !c with h s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment