With memoization this might not be so bad. The evalWhile function also seems like a poor way to check if we've reached normal form, though I have seen other code that does this. Perhaps there is a better way to do this. The eval function feels particularly awkward to me, as every type in Expr is preceded by it's equivalent function. How did you get in here, anyway Writing a Lambda Calculus interpreter in Haskell We write a rather small lambda calculus expression parser, evaluator, and repl in Haskell. S = Abst "x" (Abst "y" (Abst "z" (App (App (Var "x") (Var "z")) (App (Var "y") (Var "z")))))įor instance: λ> evalWhile (App (App (App s k) k) k) Writing a Lambda Calculus interpreter in Haskell - APOTHECA.IO And you just found out where. Here are a few applicative combinators for debugging. Sub (Sub (App a b) var env) = (App (Sub a var env) (Sub b var env))Įval a b c) = sub (Sub (eval a) b (eval c)) | otherwise = (Abst var' (Sub body var env)) module Eval whereĪpp (App (Abst var body) env) = (Sub body var env) The term x.y.xy should be written as \\x.\\y. Parser - Printer Lambda expressions should abide to the following format. The basis of the parser was implemented by Ioannis V. This code is slower than many other interpreters, and if there is a way to make the code more efficient while still conveying the reduction rules clearly, that would be an improvement. An Untyped Lambda Calculus Interpreter in Haskell This project consists of a lambda calculus expression parser using Parsec, and an eval-apply interpreter. It’s small enough to show you the whole thing in one go. Today I wrote an interpreter for one of the smallest functional languages: the lambda calculus. My goal is to represent the transformation rules listed here accurately and explicitly. A lambda calculus interpreter in Haskell A few days ago, I wrote an interpreter for a small imperative language in Haskell. (Sub (App a b) var env) -> (App (Sub a var env) (Sub b var env)) (Sub (Abst var' body) var env) -> (Abst var' (Sub body var env)) ![]() (Sub (Abst var body) var env) -> (Abst var body) ![]() (App (Abst var body) env) -> (Sub body var env) This code is a representation of lambda calculus using an AST instead of text.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |