{"id":13838410,"url":"https://github.com/yorickpeterse/pattern-matching-in-rust","last_synced_at":"2025-10-28T02:40:56.372Z","repository":{"id":164081743,"uuid":"614613604","full_name":"yorickpeterse/pattern-matching-in-rust","owner":"yorickpeterse","description":"Pattern matching and exhaustiveness checking algorithms implemented in Rust","archived":false,"fork":false,"pushed_at":"2024-10-30T19:47:27.000Z","size":74,"stargazers_count":220,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-03T03:03:06.628Z","etag":null,"topics":["compiler","pattern-matching","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yorickpeterse.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":"2023-03-16T00:27:50.000Z","updated_at":"2025-06-18T23:31:36.000Z","dependencies_parsed_at":"2024-01-15T19:43:07.528Z","dependency_job_id":"ef28e3fc-4538-46d9-b294-97535365848e","html_url":"https://github.com/yorickpeterse/pattern-matching-in-rust","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yorickpeterse/pattern-matching-in-rust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorickpeterse%2Fpattern-matching-in-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorickpeterse%2Fpattern-matching-in-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorickpeterse%2Fpattern-matching-in-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorickpeterse%2Fpattern-matching-in-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yorickpeterse","download_url":"https://codeload.github.com/yorickpeterse/pattern-matching-in-rust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorickpeterse%2Fpattern-matching-in-rust/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263250595,"owners_count":23437288,"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":["compiler","pattern-matching","rust"],"created_at":"2024-08-04T15:01:55.862Z","updated_at":"2025-10-28T02:40:56.241Z","avatar_url":"https://github.com/yorickpeterse.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Pattern matching in Rust\n\nThis repository contains a collection of pattern matching algorithms implemented\nin Rust. The goal of these implementations it to (hopefully) make it easier to\nunderstand them, as papers related to pattern matching (and papers in general)\ncan be difficult to read.\n\n## Background\n\nI ended up implementing these algorithms while investigating potential pattern\nmatching/exhaustiveness checking algorithms for [Inko](https://inko-lang.org/).\nWhile there are plenty of papers on the subject, few of them include reference\ncode, and almost all of them are really dense and difficult to read. I hope the\ncode published in this repository is of use to those wishing to implement\npattern matching/exhaustiveness.\n\n## Algorithms\n\n| Name                                          | Paper                        | Directory\n|:----------------------------------------------|:-----------------------------|:-----------\n| ML pattern compilation and partial evaluation | [PDF](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.48.1363) | [sestoft1996](./sestoft1996/)\n| How to compile pattern matching               | [PDF](https://julesjacobs.com/notes/patternmatching/patternmatching.pdf) | [jacobs2021](./jacobs2021/)\n\nOther papers I've come across (but don't necessarily want to implement):\n\n- [A generic algorithm for checking exhaustivity of pattern\n  matching](https://dl.acm.org/doi/10.1145/2998392.2998401).\n  - The Scala implementation [is found in this PR](https://github.com/lampepfl/dotty/pull/1364) (the `Space.scala` file).\n  - Swift also uses this algorithm [here](https://github.com/apple/swift/blob/3c0b1ab03f189e044303436b8aa6a27c2f93707d/lib/Sema/TypeCheckSwitchStmt.cpp)\n  - Some Reddit comments about the algorithm are [found here](https://www.reddit.com/r/ProgrammingLanguages/comments/cioxwn/a_generic_algorithm_for_checking_exhaustivity_of/)\n- [Compiling pattern matching to good decision\n  trees](https://www.cs.tufts.edu/comp/150FP/archive/luc-maranget/jun08.pdf).\n  This is about just compiling pattern matching into a decision tree, not about\n  exhaustiveness checking. If you don't know how to read the computer science\n  hieroglyphs (like me), this paper is basically impossible to understand.\n  - See also https://alan-j-hu.github.io/writing/pattern-matching.html and\n    https://contificate.github.io/compiling-pattern-matching/\n  - There's a [Rust implementation](https://github.com/SomewhatML/match-compile)\n    of this algorithm, though it doesn't perform exhaustiveness checking.\n- [Warnings for pattern\n  matching](http://pauillac.inria.fr/~maranget/papers/warn/warn.pdf). This is\n  just about producing warnings/errors for e.g. non-exhaustive patterns.\n  Similarly painful to understand as the previous paper (i.e. I gave up).\n- [The Implementation of Functional Programming\n  Languages](https://www.microsoft.com/en-us/research/publication/the-implementation-of-functional-programming-languages/).\n  This book has a chapter on pattern matching, but I gave up on it.\n\n## Requirements\n\nA recent-ish (as of 2022) Rust version that supports the 2021 edition (though I\nthink the 2018 edition should also work).\n\n## Usage\n\nEach algorithm is implemented as a library, and come with a set of unit tests\nthat you can run using `cargo test`.\n\n## Licence\n\nThe code in this repository is licensed under the\n[Unlicense](https://unlicense.org/). A copy of this license can be found in the\nfile \"LICENSE\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyorickpeterse%2Fpattern-matching-in-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyorickpeterse%2Fpattern-matching-in-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyorickpeterse%2Fpattern-matching-in-rust/lists"}