{"id":31921805,"url":"https://github.com/arthi-chaud/type-machine","last_synced_at":"2026-01-20T16:41:57.355Z","repository":{"id":309339656,"uuid":"917302105","full_name":"Arthi-chaud/type-machine","owner":"Arthi-chaud","description":"Template Haskell-based Type functions on record types in Haskell","archived":false,"fork":false,"pushed_at":"2025-09-02T10:45:57.000Z","size":133,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-02T12:29:37.025Z","etag":null,"topics":["haskell","template-haskell","types"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/type-machine","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Arthi-chaud.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2025-01-15T18:21:21.000Z","updated_at":"2025-09-02T10:46:00.000Z","dependencies_parsed_at":"2025-08-11T11:32:18.565Z","dependency_job_id":"4713ff66-562d-4b3b-87be-ef8c8bc6656f","html_url":"https://github.com/Arthi-chaud/type-machine","commit_stats":null,"previous_names":["arthi-chaud/type-machine"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Arthi-chaud/type-machine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arthi-chaud%2Ftype-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arthi-chaud%2Ftype-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arthi-chaud%2Ftype-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arthi-chaud%2Ftype-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Arthi-chaud","download_url":"https://codeload.github.com/Arthi-chaud/type-machine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arthi-chaud%2Ftype-machine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017088,"owners_count":26085984,"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-10-13T02:00:06.723Z","response_time":61,"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":["haskell","template-haskell","types"],"created_at":"2025-10-13T22:54:18.863Z","updated_at":"2025-10-13T22:54:20.468Z","avatar_url":"https://github.com/Arthi-chaud.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Type Machine\n\nTypeScript offers [*Utility Types*](https://www.typescriptlang.org/docs/handbook/utility-types.html), which allows creating a type from another.\nThere is no way of doing this in Haskell. You have to maintain all your types yourselves, and handle conversions from one to another yourself.\n\n`type-machine` brings a solution to this problem. Using Template Haskell, generate new types using Type-Script-inspired functions like `omit`, `pick` and `record`.\nIt can also generate a conversion type-class that allows you to access fields and convert one type to another.\n\n- Requirements\n    - Requires a couple of language extensions (see example)\n    - Input ADT must have exactly one record constructor\n- Limitations\n    - Does not support type parameters yet\n    - `require` and `partial` only work with `Maybe` fields \n\n## Examples\n\n```haskell\n{-# LANGUAGE TemplateHaskell #-}\n{-# LANGUAGE DuplicateRecordFields #-}\n\ndata User = User {\n    id :: Int,\n    name :: String,\n    email :: Maybe String\n}\n\n$(type_ \"UserWithEmail\" (required [\"email\"] \u003c::\u003e ''User))\n-- data UserWithEmail = UserWithEmail {\n--     id :: Int,\n--     name :: String,\n--     email :: String\n-- }\n\n$(type_ \"UserWithoutId\" (omit [\"id\"] \u003c::\u003e ''User))\n-- data UserWithoutId = UserWithoutId {\n--     name :: String,\n--     email :: String\n-- }\n\n$(type_ \"UserId\" (pick [\"id\"] \u003c::\u003e ''User))\n-- data UserId = UserId {\n--     id :: Int\n-- }\n\n$(type_ \"Vector3\" (record [\"x\", \"y\", \"z\"] [t|Int|]))\n-- data Vector3 = Vector3 {\n--     x :: Int,\n--     y :: Int,\n--     z :: Int\n-- }\n\n-----\n-- Type Parameters\n-----\n\ndata MyMaybe a = { content :: Maybe a }\n\n$(type_ \"MyString\" (apply [t|String|] \u003c::\u003e ''MyMaybe))\n-- data MyString = MyString { \n--     content :: Maybe String\n-- }\n\n-----\n-- Is\n-----\n\n$(declareIs ''User)\n-- class IsUser a where\n--     getId :: a -\u003e Int\n--     getName :: a -\u003e String\n--     getEmail :: a -\u003e String\n--     setId :: Int -\u003e a -\u003e a\n--     setName :: String -\u003e a -\u003e a\n--     setEmail :: String -\u003e a -\u003e a\n--\n-- instance IsUser User where\n--     getId = id\n--     getName = name\n--     getEmail = email\n--     setId = ...\n--     setName = ...\n--     setEmail = ...\n\n$(type_ \"UserWithoutEmail\" (omit [\"email\"] \u003c::\u003e ''User))\n$(deriveIs ''User ''UserWithoutEmail)\n-- instance IsUser UserWithoutEmail where\n--     ...\n\n$(type_ \"UserWithoutId\" (omit [\"id\"] \u003c::\u003e ''User))\n$(deriveIs ''User ''UserWithoutId) -- Will fail\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthi-chaud%2Ftype-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farthi-chaud%2Ftype-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthi-chaud%2Ftype-machine/lists"}