{"id":30063404,"url":"https://github.com/therealprohacker/lambda","last_synced_at":"2026-05-17T11:33:03.797Z","repository":{"id":147753306,"uuid":"604645384","full_name":"theRealProHacker/lambda","owner":"theRealProHacker","description":"A lambda calculus evaluator in both Haskell and Python","archived":false,"fork":false,"pushed_at":"2026-02-23T04:42:35.000Z","size":36,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-23T12:51:27.812Z","etag":null,"topics":["beta-reduction","functional-programming","haskell","lambda-calculus","python3"],"latest_commit_sha":null,"homepage":"https://therealprohacker.github.io/lambda/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theRealProHacker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-02-21T13:54:42.000Z","updated_at":"2026-02-23T04:42:38.000Z","dependencies_parsed_at":"2024-04-06T02:27:47.388Z","dependency_job_id":"da3fce25-5f15-4738-9787-9d38d934e1e5","html_url":"https://github.com/theRealProHacker/lambda","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/theRealProHacker/lambda","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theRealProHacker%2Flambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theRealProHacker%2Flambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theRealProHacker%2Flambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theRealProHacker%2Flambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theRealProHacker","download_url":"https://codeload.github.com/theRealProHacker/lambda/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theRealProHacker%2Flambda/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33136741,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T09:28:26.183Z","status":"ssl_error","status_checked_at":"2026-05-17T09:27:52.702Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beta-reduction","functional-programming","haskell","lambda-calculus","python3"],"created_at":"2025-08-08T04:24:22.934Z","updated_at":"2026-05-17T11:33:03.792Z","avatar_url":"https://github.com/theRealProHacker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \\ambda - A Lambda calculator written in Haskell\n\n\u003e Inspired by the course \"Funktionale Programmierung\" @ FU Berlin\n\nA suite of programs to evaluate lambda calculus expressions. Try it out right now [on the web](https://therealprohacker.github.io/lambda/)\n\n# How to run locally\n\nFirst you need to install git and clone the repo\n```shell\n\u003e git clone https://github.com/theRealProHacker/lambda.git\n\u003e cd lambda\n```\n\n## Python\n\nRun the Python script very easily. No dependencies required but at least Python 3.10!\n\n```shell\n\u003e py pylambda.py\n```\n\nThe script will then ask you to input your lambda expression and evaluate it, when you hit enter. \n\n## Haskell\n\nThe amazing part is that it's about 100 lines of code with a lot of comments and a cli attached. Without all comments, type signatures and the cli interface, its a bit less than half of that!\nMake sure that you have [`ghc`](https://www.haskell.org/ghc/) installed and in your Path. Then you can compile [`lambda.hs`](lambda.hs).\n\n```shell\n\u003e ghc --make lambda\n```\n\nNow you can run the executable like this.\n\n```shell\n\u003e lambda (\\kbc.k(bb)c)(\\xy.xya)(\\f.f)\n(\\c.ac)\n```\n\n\u003e Note: These examples are for Windows. On Linux replace `lambda` with `./lambda`\n\nAs you may have noticed, the λ is replaced with a back slash (\\\\) \ninspired by the notation for lambda functions in Haskell. \nAlso whitespaces have a significance as they end the body of a function.\n\n```shell\n\u003e lambda \\kbc.k(bb)c \\xy.xya \\f.f\n(\\c.ca)\n```\n\n### Run without compiling\nAlternatively you can run the code without compiling it.\n\n```shell\n\u003e runhaskell lambda \\kbc.k(bb)c \\xy.xya \\f.f\n(\\c.ca)\n```\n\n### Running in debug mode\n\nIn [`lambda.hs`](lambda.hs) you can see this line\n\n```hs\ndebug = False\n```\n\nIf you set `debug` to `True` you can see the steps of the reduction process, which is perfect for introspection because it also dumps the ast at every step.\n\n### In the interpreter\n\nYou can also run [`ilambda.hs`](ilambda.hs) in an interactive ghci session. But don't forget to use double backslashes (\\\\\\\\) (which in Markdown ironically needs 4 backslashes). \n\n```shell\n\u003e ghci ilambda\nGHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help\n[1 of 1] Compiling Main             ( ilambda.hs, interpreted )\nOk, one module loaded.\n*Main\u003e (\\a.a)b\n\"*** Exception: Stray . found \nCallStack (from HasCallStack):\n  error, called at ilambda.hs:30:32 in main:Main\n*Main\u003e beta \"(\\\\a.a)b\"\n\"b\"\n```\n\n# **WTF** is lambda calculus\n\nFrom [Wikipedia - the free encyclopedia](https://en.wikipedia.org/wiki/Lambda_calculus)\n\n\u003e Lambda calculus (also written as λ-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation that can be used to simulate any Turing machine. It was introduced by the mathematician Alonzo Church in the 1930s as part of his research into the foundations of mathematics.\n\nIt is basically a first programming language from the 1930s before computers even existed! To use it here replace the lambda symbol (λ) with a back slash (\\). \n\n# The future of this\n\n## Files and variables\n\nGoing further I'd like to introduce a file input mode where you can define variables that can then be used globally.\n\n```hs\n// define Variables\nTrue = (\\tf.t)\nFalse = (\\tf.f)\n\n// and use them\nAnd = \\ab.ab(False)\nOr = \\ab.a(True)b\n```\n\nBut that'd just become more and more like Haskell.\n\n## Haskell transpiler\n\nCombined with the above you could convert your lambda expressions into haskell code. \n\n`x = \\ab.ab` would become\n\n```hs\nx a b = a b\n```\n\n# Random Fun\nJust for fun I put the smallest \"possible\" compressed version of [`ilambda.hs`](ilambda.hs) (the already compressed version) here, which is just 5 lines of code. I'll bet you that you can't make it much smaller. The code is technically not exactly the same because errors are thrown implicitly but nice and shiny explicit errors that tell you exactly where you went wrong aren't really a requirement. \n\n```hs\ndata Expression = Var Char | Func String Expression | Appl [Expression] deriving (Show, Eq);showExpr x = case x of (Var c) -\u003e [c]; (Func head body) -\u003e \"(\\\\\" ++ head ++ \".\" ++ (showExpr body) ++ \")\"; (Appl xs) -\u003e foldl (++) [] $ map showExpr xs;\n_split_on s1 (c:s2) x = if c == x then (s1, s2) else _split_on (s1++[c]) s2 x;split_closing_paren' n before (c:rest) = if c == ')' then if n==0 then (reverse before, rest) else split_closing_paren' (n-1) before rest else if c=='(' then split_closing_paren' (n+1) before rest else split_closing_paren' n (c:before) rest;tokenize exprs str = case str of \"\"-\u003eexprs; '\\\\':rest -\u003e let (head, body) = _split_on \"\" rest '.' in if ' ' `elem` body then let (body', rest') = _split_on \"\" body ' ' in tokenize ((Func head $ parse body'):exprs) rest' else tokenize ((Func head $ parse body):exprs) \"\"; '(':rest -\u003e let (inner, after) = (split_closing_paren' 0 \"\" rest) in tokenize ((parse inner): exprs) after; ' ':rest -\u003e tokenize exprs rest; x:rest -\u003e tokenize (Var x:exprs) rest;\nparse = Appl . reverse . tokenize [];replaceArg c e expr = case expr of var@(Var x) -\u003e if c==x then e else var; func@(Func head body) -\u003e if c `elem` head then func else Func head (replaceArg c e body); (Appl exprs) -\u003e Appl $ map (replaceArg c e) exprs;\nreduce x = case x of (Appl [x]) -\u003e reduce x; (Appl ((Func [] body):rest)) -\u003e reduce $ Appl (body:rest); (Appl ((Func [param] body):arg:arg_rest)) -\u003e reduce $ Appl (replaceArg param arg body:arg_rest); (Appl ((Func (param1:param_rest) body):arg1:arg_rest)) -\u003e reduce $ Appl (Func param_rest (replaceArg param1 arg1 body):arg_rest); (Appl exprs) -\u003e reduce $ Appl $ map reduce exprs; (Func head body) -\u003e Func head $ reduce body; _ -\u003e x;\nbeta = showExpr . reduce . parse\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftherealprohacker%2Flambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftherealprohacker%2Flambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftherealprohacker%2Flambda/lists"}