Skip to content

Instantly share code, notes, and snippets.

@EduardoRFS
Created November 2, 2022 23:15
Show Gist options
  • Save EduardoRFS/36c74638b414f69c8dd23415ca02a988 to your computer and use it in GitHub Desktop.
Save EduardoRFS/36c74638b414f69c8dd23415ca02a988 to your computer and use it in GitHub Desktop.
type term = Var of string | Lam of string * term | App of term * term
type value = Closure of ((string * value) list * string * term)
let rec eval env term =
match term with
| Var var -> List.assoc var env
| Lam (param, body) -> Closure (env, param, body)
| App (lambda, argument) -> (
let lambda = eval env lambda in
let argument = eval env argument in
match lambda with
| Closure (env, param, body) ->
let env = (param, argument) :: env in
eval env body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment