{"id":15401254,"url":"https://github.com/tmcdonell/embedded-pattern-matching","last_synced_at":"2025-04-16T02:28:30.211Z","repository":{"id":53180890,"uuid":"300012193","full_name":"tmcdonell/embedded-pattern-matching","owner":"tmcdonell","description":"A language to demonstrate embedded pattern matching","archived":false,"fork":false,"pushed_at":"2022-09-15T21:11:57.000Z","size":117,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T04:12:00.074Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmcdonell.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}},"created_at":"2020-09-30T18:15:58.000Z","updated_at":"2023-07-05T13:17:41.000Z","dependencies_parsed_at":"2023-01-18T09:15:43.438Z","dependency_job_id":null,"html_url":"https://github.com/tmcdonell/embedded-pattern-matching","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/tmcdonell%2Fembedded-pattern-matching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmcdonell%2Fembedded-pattern-matching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmcdonell%2Fembedded-pattern-matching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmcdonell%2Fembedded-pattern-matching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmcdonell","download_url":"https://codeload.github.com/tmcdonell/embedded-pattern-matching/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249184408,"owners_count":21226363,"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-01T15:57:03.067Z","updated_at":"2025-04-16T02:28:30.177Z","avatar_url":"https://github.com/tmcdonell.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"embedded-pattern-matching\n=========================\n\nImplementation to accompany the paper _Embedded Pattern Matching_ by Trevor L.\nMcDonell, Joshua D. Meredith, and Gabriele Keller, Haskell Symposium 2022.\n([pdf](https://dl.acm.org/doi/10.1145/3546189.3549917), [slides](https://speakerdeck.com/tmcdonell/embedded-pattern-matching), video (TBD))\n\n\u003c!--\n```\n@inproceedings{embedded_pattern_matching,\n  author    = {McDonell, Trevor L. and Meredith, Joshua D. and Keller, Gabriele},\n  title     = {Embedded Pattern Matching},\n  year      = {2022},\n  doi       = {10.1145/3546189.3549917},\n  booktitle = {Haskell Symposium},\n  pages     = {123–136},\n  numpages  = {14},\n}\n```\n--\u003e\n\nWith this technique we can use pattern matching in the _host_ language to\nintroduce case expressions in the _embedded_ language, in much the same way the\nuser would do in the host language. This enables a natural and user-friendly\nembedding of user-defined algebraic data types into the embedded language. For\nexample:\n\n```haskell\nlength :: Elt a =\u003e Exp (List a) -\u003e Exp Int\nlength xs =\n  let -- the core of the technique demonstrated here:\n      body = match \\case\n        Nil_        -\u003e int 0\n        Cons_ _ xs' -\u003e int 1 `Add` App (Var l) xs'\n\n      -- need to add explicit variables, application, abstraction, because we\n      -- demonstrate the technique using a first order embedding:\n      l = Idx \"length\"\n      v = Idx \"xs\"\n  in\n  Let l (Lam v (body (Var v))) (App (Var l) xs)\n```\n\nThis repository contains three versions of the idea:\n\n## haskell-surface\n\nThis implementation in Haskell uses an embedded language where the AST witnesses\nterms based on the _surface_ type of those terms (that is, the user's view of a\ndata type). This is the language described in the paper.\n\nSupports sum, product, and (mutually) recursive data types. Includes the\nGHC.Generics and TemplateHaskell automation described in the paper.\n\nSee `haskell-surface/README.md` for more information.\n\n\n## haskell-repr\n\nThis implementation uses an embedded language where the AST witnesses terms\nbased on the _representation_ type of those terms. This is because it follows\nthe style used by the embedded language from the case study (Accelerate). There\nare overall only minor differences between this language and that from the\nimplementation of `haskell-surface` as described in the paper.\n\nSupports sum and product data types. Includes all the GHC.Generics and\nTemplateHaskell automation discussed in the paper.\n\nSee `haskell-repr/README.md` for more information.\n\n\n## scala-surface\n\nThis implementation in Scala is similar to the formulation in `haskell-surface`,\nwith some straightforward changes as described in the paper to account for\ndifferences between Scala and Haskell.\n\nSupports sum, product, and recursive data types.\n\nSee `scala-surface/README.md` for more information.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmcdonell%2Fembedded-pattern-matching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmcdonell%2Fembedded-pattern-matching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmcdonell%2Fembedded-pattern-matching/lists"}