{"id":17898755,"url":"https://github.com/mrvplusone/lambda-in-haskell","last_synced_at":"2025-04-03T05:15:11.708Z","repository":{"id":132435998,"uuid":"47447991","full_name":"MrVPlusOne/Lambda-In-Haskell","owner":"MrVPlusOne","description":"A haskell library for lamdba calculus.","archived":false,"fork":false,"pushed_at":"2016-08-04T09:19:16.000Z","size":1141,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-02-08T19:11:54.477Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","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/MrVPlusOne.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}},"created_at":"2015-12-05T08:09:55.000Z","updated_at":"2022-01-10T16:32:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"7c925468-e864-425c-a02d-37100973a50f","html_url":"https://github.com/MrVPlusOne/Lambda-In-Haskell","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrVPlusOne%2FLambda-In-Haskell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrVPlusOne%2FLambda-In-Haskell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrVPlusOne%2FLambda-In-Haskell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrVPlusOne%2FLambda-In-Haskell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrVPlusOne","download_url":"https://codeload.github.com/MrVPlusOne/Lambda-In-Haskell/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246939239,"owners_count":20857922,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-10-28T15:38:50.624Z","updated_at":"2025-04-03T05:15:11.691Z","avatar_url":"https://github.com/MrVPlusOne.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lambda-In-Haskell\n### A haskell library for lambda calculus.\n\nThis is a simple library I wrote while learning Type theory and Haskell.\n\n## Usage and examples:\n\nFirst, `cd` into the project folder and load *Playground.hs* into ghci:\n\n```\ncd Path-To-Project\n$ ghci Playground.hs\n```\n\nThis *Playground.hs* file will import those interesting functions exported by other modules for you.\nThen you can try with those functions:\n\n#### 1. Untyped lambda calculus\n\nUntyped lambda calculus are the foundation of this project.\n\n* You can parse lambda terms\n\n`ghci\u003e let e1 = parseExpr \"λf x. f y x\"`\n\n```\nghci\u003e :t e1\ne1 :: Term  -- 'Term' is the type of a lambda term\nghci\u003e e1\nλf x. f y x -- pretty print of a term\n```\n\n* Then you can find out free variables\n\n```\nghci\u003e freeVars e1\nfromList [\"y\"]  -- A set of variable names is returned\n```\n\n* You can substitute a variable by another term use `/:` or `substitude`:\n\n```\nghci\u003e (\"y\", parseExpr \"u v\") /: e1  -- this will replace all free occurrence of `y` in `e1` by `u v`\nλf x. f (u v) x\n```\n\n```\nghci\u003e (\"y\", parseExpr \"λ y. x\") /: (parseExpr \"λ x. x y\")\nλu. u (λy. x) -- notice that the outer variable `x` has been renamed to `u` automatically.\n```\n\n* Find all subterms\n\n```\nghci\u003e subTerms it\nfromList [f,u,v,x,f (u v),u v,f (u v) x,λf x. f (u v) x,λx. f (u v) x]\n```\n\n* Lambda calculus isn't of much use if it can't *calculate*. So we need *beta-reduction*.\n\n```\nghci\u003e tryReduceInSteps 10 (parseExpr \"(λ x y. y x) u v\")  -- let's flip u v\nJust v u -- you get the result!\n```\n\nBut not all terms have *beta-normal forms*, that's why the result type is a `Maybe Term`, and you must *tryReduceInSteps*.\n\nFor example, the famous term Ω has an infinite reduction sequence:\n\n```\nghci\u003e omega\n(λx. x x) (λx. x x)\n\nghci\u003e tryReduceInSteps 10 omega\nNothing\n```\n\nBy the way, you can enter the above term like this:\n\n```\nghci\u003e (lambda \"x\" (Var \"x\")) # (lambda \"x\" (Var \"x\"))  -- '#' is the 'apply' operator\n(λx. x) (λx. x)\n```\n\n*tryReduceInSteps* will search through all possible reduction paths trying to get a normal-form result.\n\nSo, term like '(λx. y) Ω' can be reduced:\n\n```\nghci\u003e let e2 = lambda \"x\" (Var \"y\") # omega\nghci\u003e tryReduceInSteps 10 e2\nJust y\nghci\u003e reduceChoices e2  -- list all possible β-reduction paths\n[y,(λx. y) ((λx. x x) (λx. x x))]\n```\n\n* You can also use `betaEqual` to check β-equivalence.\n\n#### 2. Simply typed lambda calculus\n\nSimply typed lambda is provided by 'TypedTerm' module\n\n* Just use `inferThenShow` to type a term\n\n```\nghci\u003e putStrLn $ inferThenShow e1  -- remember e1 == λf x. f y x\nλf: t2 -\u003e t1 -\u003e t0. λx: t1. {f: t2 -\u003e t1 -\u003e t0} {y: t2} {x: t1} : (t2 -\u003e t1 -\u003e t0) -\u003e t1 -\u003e t0\nghci\u003e parseinfer \"λx y . x(λz . y)y\"\nλx: (t1 -\u003e t2) -\u003e t2 -\u003e t0. λy: t2. {x: (t1 -\u003e t2) -\u003e t2 -\u003e t0} (λz: t1. {y: t2}) {y: t2} : ((t1 -\u003e t2) -\u003e t2 -\u003e t0) -\u003e t2 -\u003e t0\n```\n\nThat gives back every variable's type. If you don't want this string result, use `inferType` instead.\n\n```\nghci\u003e parseinfer \"λx y . x(λz . x)y\"\ncan't construct infinite type: t8 = (t7 -\u003e t8) -\u003e t5 -\u003e t4\n\tin x\n\tin x (λz. x)\n\tin x (λz. x) y\n\tin λy. x (λz. x) y\n\tin λx y. x (λz. x) y\n```\n\n#### 3. Visualization through html\n\nUse `inferConstraintHtml :: Term -\u003e TyConstraintTree -\u003e Html` in the HtmlPrint module to convert a term along with a TyConstraintTree into html.\n\nFor example:\n\n```\n:l Playground.hs\nparseToHtml \"λf x. x\"\n```\n\nThis will output the result into 'result.html' file. Open it use a browser gives:\n\n![alt tag](visual.png)\n\nYou can mouse over any element in this term to see its type as a tooltip.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrvplusone%2Flambda-in-haskell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrvplusone%2Flambda-in-haskell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrvplusone%2Flambda-in-haskell/lists"}