Lambda calculus interpreter haskell7/9/2023 ![]() ![]() The original interpreter of Poly is slow because it emulates beta reduction on top of Haskell, but our implementation avoids this overhead by utilizing the host system’s support for beta-reduction. x is easier to read and write than Lam 'x' (Lam 'y' (Var 'x'))) and secondly, it lets us write lambda calculus outside of Haskell, which comes in handy when we're building our interpreter later. The key idea is to replace Lam and Ap constructors with Haskell’s built-in lambda and application constructs. Having a parser serves a few purposes: first, it lets us use a better format for our lambda calculus code ( \ x y. The next step is to compile expressions into a fixed, finite combinators. (Note that $IF can be a function because we piggy back on the lazy evaluation of the host language, Haskell.) Compilation to SKI combinators Suppose TM is a lambda term that simulates a Turing Machine. $IF, $FIX, $ADD, $SUB, $MUL, $EQL will be provided as primitive functions. If, Fix are Op are desugared into function applications. They terminated when they reached an answer in Weak Head Normal Form. In lecture, we wrote several interpreters for the Lambda Calculus. Let’s start the discussion by writing a lambda calculus interpreter. In this post, I am going to explain how we can implement a call-by-value interpreter using various methods. In my implementation I needed a parser, an. There are several steps of the process that are missed because they are built into the Racket language. I decided I would try to implement it in Haskell instead of Racket. This whole project is based on this post by Matt Might. N = case op of Add -> "$ADD" Sub -> "$SUB" Mul -> "$MUL" Eql -> "$EQL"ĭesugar function converts let x = e in body into (\x -> body) e. A Normal Order Normal Form Interpreter for the Lambda Calculus Now, we will describe the actual homework. This difference in evaluation model poses some challenges in writing a call-by-value interpreter in Haskell. Compiling and Interpreting the Lambda Calculus in Haskell. Desugar ( App fun arg) = App (desugar fun) (desugar arg)ĭesugar ( Lam x body) = Lam x (desugar body)ĭesugar ( Let x e body) = App ( Lam x (desugar body)) (desugar e)ĭesugar ( If cond tr fl) = foldl App ( Var "$IF") argsĭesugar ( Fix e) = App ( Var "$FIX") (desugar e)ĭesugar ( Op op a b) = foldl App ( Var n) args ![]()
0 Comments
Leave a Reply. |