{"id":19722051,"url":"https://github.com/tensor-fusion/coquand-sml","last_synced_at":"2026-02-16T19:40:10.914Z","repository":{"id":251331460,"uuid":"837097935","full_name":"tensor-fusion/Coquand-SML","owner":"tensor-fusion","description":"A bidirectional dependent type checker in Standard ML","archived":false,"fork":false,"pushed_at":"2024-08-02T08:10:11.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T00:32:24.557Z","etag":null,"topics":["dependent-types","sml","type-checker"],"latest_commit_sha":null,"homepage":"","language":"Standard ML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tensor-fusion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-08-02T07:56:00.000Z","updated_at":"2025-02-11T20:45:55.000Z","dependencies_parsed_at":"2024-08-02T09:27:09.936Z","dependency_job_id":"c3c92a56-427f-47d5-a158-d24c893bd4b9","html_url":"https://github.com/tensor-fusion/Coquand-SML","commit_stats":null,"previous_names":["tensor-fusion/coquand-sml"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tensor-fusion/Coquand-SML","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensor-fusion%2FCoquand-SML","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensor-fusion%2FCoquand-SML/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensor-fusion%2FCoquand-SML/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensor-fusion%2FCoquand-SML/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tensor-fusion","download_url":"https://codeload.github.com/tensor-fusion/Coquand-SML/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensor-fusion%2FCoquand-SML/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276562628,"owners_count":25664433,"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","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["dependent-types","sml","type-checker"],"created_at":"2024-11-11T23:16:18.385Z","updated_at":"2025-09-23T11:11:22.455Z","avatar_url":"https://github.com/tensor-fusion.png","language":"Standard ML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bidirectional dependent type checker in Standard ML\n\nThis is a Standard ML implementation of a bidirectional dependent type checker based on Coquand's algorithm [1].\n\n## Type system\n\nThe type checker is quite simple, it implements a core dependent type system with just:\n\n- Lambda abstractions (λ-terms)\n- Let expressions\n- Function application\n- Dependent function types (Π-types)\n- A single universe `Type`\n\n## Core types\n\n```sml\ndatatype Expression = \n    Variable of Identifier\n    | Application of Expression * Expression\n    | Abstraction of Identifier * Expression\n    | LetBinding of Identifier * Expression * Expression * Expression\n    | PiType of Identifier * Expression * Expression\n    | BaseType\n\ndatatype Value = \n    GenericValue of int\n    | AppValue of Value * Value\n    | TypeValue\n    | Closure of (Identifier * Value) list * Expression\n\n```\n\nThe `expression` type represents the language AST and the `value` represents the semantic domain, using closures to handle envs for lexical scoping.\n\n## Type checking algorithm\n\nThe core of the type checker uses a bidirectional approach implemented in the mutually recursive functions `checkExpression` and `inferExpression`. \n\n```sml\ncheckExpression (k, ρ, Γ) e A = ...\ninferExpression (k, ρ, Γ) e = ...\n```\n\nThese correspond to the judgments:\n\n$$\n\\Gamma \\vdash e \\Leftarrow A \\text{ (checking)}\n$$\n\n$$\n\\Gamma \\vdash e \\Rightarrow A \\text{ (inference)}\n$$\n\n## Normalization\n\nThe `normalFormValue` fn implements a simple Normalization by Evaluation strategy to compare types up to β-equivalence.\n\n   ```sml\n  normalFormValue value =\n      case value of\n          AppValue (func, arg) =\u003e applyValue (normalFormValue func) (normalFormValue arg)\n        | Closure (env, body) =\u003e evaluate env body\n        | _ =\u003e value\n   ```\n\n## Example\n\nHere's how we can represent and type-check the polymorphic identity function:\n\n```sml\nval identityFunction = Abstraction (\"A\", Abstraction (\"x\", Variable \"x\"))\nval identityType = PiType (\"A\", TypeConstant, PiType (\"x\", Variable \"A\", Variable \"A\"))\n\nval test = typecheck identityFunction identityType\n```\n\nThis corresponds to the $\\Pi$-type:\n\n$$\n\\Pi (A : \\textsf{Type}) . \\Pi (x : A) . A\n$$\n\n## TODO\nSo far this just implements the paper but some stuff to add might be:\n\n- [ ] Σ-types\n- [ ] Agda-like hierarchy of universes\n- [ ] Inductive types????\n\n## References\n\n[1] Coquand, T. (1996). An algorithm for type-checking dependent types","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensor-fusion%2Fcoquand-sml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftensor-fusion%2Fcoquand-sml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensor-fusion%2Fcoquand-sml/lists"}