Skip to content

Instantly share code, notes, and snippets.

@wolverian
Created October 8, 2014 20:24
Show Gist options
  • Save wolverian/b676a6c068d4bea2aa0c to your computer and use it in GitHub Desktop.
Save wolverian/b676a6c068d4bea2aa0c to your computer and use it in GitHub Desktop.
(: interp (Expr-C Env Store -> Result))
(define (interp expr env store)
(match expr
[(num-c n) (v*s (num-v n) store)]
[(plus-c l r) (match-let* ([(v*s v-l s-l) (interp l env store)]
[(v*s v-r s-r) (interp r env s-l)])
(v*s (num+ v-l v-r) s-r))]
[(mult-c l r) (match-let* ([(v*s v-l s-l) (interp l env store)]
[(v*s v-r s-r) (interp r env s-l)])
(v*s (num* v-l v-r) s-r))]
[(app-c f arg-val) (match-let* ([(v*s (clos-v a b f-e) f-s) (interp f env store)]
[(v*s a-v a-s) (interp arg-val env f-s)]
[where (new-loc)])
(interp b
(extend-env (bind a where) f-e)
(override-store (cell where a-v) a-s)))]
[(id-c n) (v*s (fetch (lookup n env) store) store)]
[(lam-c arg body) (v*s (clos-v arg body env) store)]
[(box-c a) (match-let ([(v*s v s) (interp a env store)])
(let ([where (new-loc)])
(v*s (box-v where)
(override-store (cell where v)
s))))]
[(unbox-c a) (match-let ([(v*s (box-v loc) s) (interp a env store)])
(v*s (fetch loc s) s))]
[(set-box-c b v) (match-let* ([(v*s (box-v loc) s-b) (interp b env store)]
[(v*s v-v s-v) (interp v env s-b)])
(v*s v-v (override-store (cell loc v-v) s-v)))]
[(seq-c a b) (match-let ([(v*s v s) (interp a env store)])
(interp b env s))]))
@erikkaplun
Copy link

how were you able to use match-let/match-let* in plai-typed? and the (: interp (Expr-C Env Store -> Result)) style type annotation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment