Created
          October 1, 2025 22:04 
        
      - 
      
- 
        Save EduardoRFS/605816f58b4b4ea05938bbcf462701bb to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | type term = T_var of var | T_lambda of var * term | T_apply of term * term | |
| and var = { mutable to_ : term } | |
| let v_with var ~to_ k = | |
| let prev = var.to_ in | |
| var.to_ <- to_; | |
| let value = k () in | |
| var.to_ <- prev; | |
| value | |
| let v_def var k = v_with var ~to_:(T_var var) k | |
| let rec eval term = | |
| match term with | |
| | T_var var -> var.to_ | |
| | T_lambda (var, body) -> | |
| let body = v_def var (fun () -> eval body) in | |
| T_lambda (var, body) | |
| | T_apply (funct, arg) -> ( | |
| let funct = eval funct in | |
| let arg = eval arg in | |
| match funct with | |
| | T_lambda (var, body) -> v_with var ~to_:arg (fun () -> eval body) | |
| | T_var _ | T_apply (_, _) -> T_apply (funct, arg)) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment