Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Last active January 1, 2016 10:29
Show Gist options
  • Save ympbyc/8132102 to your computer and use it in GitHub Desktop.
Save ympbyc/8132102 to your computer and use it in GitHub Desktop.
CoffeeCup in Carrot
(= (cup Number CupState) n n)
(= (broken-cup CupState) nil)
(= (fill Number CupEvent) n (cons 'fill n))
(= (spill Number CupEvent) n (cons 'spill n))
(= (drop CupEvent) (cons 'drop nil))
(= (next-cup-state CupEvent CupState CupState)
ce cs
(=? (fst ce) 'fill (cup (+ cs (snd ce)))
(=? (fst ce) 'spill (cup (- cs (snd ce)))
broken-cup)))
(= (coffee-cup Minkowski)
(fold next-cup-state
(cup 100)
[(spill 20) (fill 10) (spill 90) drop]))
(= (cup Number (CupState _Cup)) x x)
(= (broken-cup (CupState _Broken)) nil)
(= (spill Number (CupEvent _Spill)) n n)
(= (fill Number (CupEvent _Fill)) n n)
(= (drop (CupEvent _Drop)) nil)
(= (next-cup-state (CupEvent _Fill) (CupState _Cup) (CupState _Cup))
x c (cup (+ c x)))
(= (next-cup-state (CupEvent _Spill) (CupState _Cup) (CupState _Cup))
x c (cup (- c x)))
(= (next-cup-state (CupEvent _Drop) (CupState _) (CupState _Broken))
_ _ broken-cup)
(= (next-cup-state (CupEvent _) (CupState _Broken) (CupState _Broken))
_ _ broken-cup)
(fold next-cup-state (cup 100) [(spill 10) (fill 5) (spill 30) drop (fill 2)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment