Skip to content

Instantly share code, notes, and snippets.

@philipschwarz
Created April 11, 2020 16:07
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 philipschwarz/a1b5f3d7577489c6332b230aa7faae46 to your computer and use it in GitHub Desktop.
Save philipschwarz/a1b5f3d7577489c6332b230aa7faae46 to your computer and use it in GitHub Desktop.
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