Skip to content

Instantly share code, notes, and snippets.

@ghulette
Last active October 6, 2016 14:51
Show Gist options
  • Save ghulette/fd4df8c7c0400136c74d5d3df7a23a72 to your computer and use it in GitHub Desktop.
Save ghulette/fd4df8c7c0400136c74d5d3df7a23a72 to your computer and use it in GitHub Desktop.
type value = int
type ptr = value ref
type st = unit
type 'a imp =
| New of value * (ptr -> 'a imp)
| Read of ptr * (value -> 'a imp)
| Write of ptr * value * 'a imp
| While of (st -> bool) * unit imp * 'a imp
| Return of 'a
let rec interp = function
| New (v,k) -> fun () -> let p = ref v in interp (k p)
| Read (p,k) -> let v = !p in interp (k v)
| Write (p,v,k) -> p := v; interp k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment