Skip to content

Instantly share code, notes, and snippets.

@mikaelsouza
Forked from EduardoRFS/lc.ml
Created November 2, 2022 23:19
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 mikaelsouza/518da028ecc72484597a910bad70ee9a to your computer and use it in GitHub Desktop.
Save mikaelsouza/518da028ecc72484597a910bad70ee9a 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