{"id":16313958,"url":"https://github.com/lysxia/generic-data","last_synced_at":"2025-04-05T06:06:19.241Z","repository":{"id":31163848,"uuid":"122157444","full_name":"Lysxia/generic-data","owner":"Lysxia","description":"Generic data types in Haskell, utilities for GHC.Generics","archived":false,"fork":false,"pushed_at":"2024-10-19T23:02:12.000Z","size":276,"stargazers_count":44,"open_issues_count":8,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-20T12:30:19.601Z","etag":null,"topics":["deriving","generics","haskell"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/generic-data","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/Lysxia.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}},"created_at":"2018-02-20T05:03:17.000Z","updated_at":"2024-10-19T23:02:00.000Z","dependencies_parsed_at":"2024-03-28T12:25:16.207Z","dependency_job_id":"4e7a0ad3-5504-459f-b24f-d93300c6ce10","html_url":"https://github.com/Lysxia/generic-data","commit_stats":{"total_commits":275,"total_committers":4,"mean_commits":68.75,"dds":"0.050909090909090904","last_synced_commit":"4459bd28fe653b4db2c19de21024cb3806dad09c"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Fgeneric-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Fgeneric-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Fgeneric-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Fgeneric-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lysxia","download_url":"https://codeload.github.com/Lysxia/generic-data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294536,"owners_count":20915340,"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":["deriving","generics","haskell"],"created_at":"2024-10-10T21:52:47.205Z","updated_at":"2025-04-05T06:06:19.209Z","avatar_url":"https://github.com/Lysxia.png","language":"Haskell","readme":"# Generic data types in Haskell\n\n[![Hackage](https://img.shields.io/hackage/v/generic-data.svg)](https://hackage.haskell.org/package/generic-data)\n[![GitHub CI](https://github.com/Lysxia/generic-data/actions/workflows/haskell-ci.yml/badge.svg)](https://github.com/Lysxia/generic-data/actions)\n\nUtilities for `GHC.Generics`.\n\n## Generic deriving for standard classes\n\n### Example: generically deriving Semigroup instances for products\n\nSemi-automatic method using `gmappend`\n\n```haskell\ndata Foo a = Bar [a] [a] deriving Generic\n\ninstance Semigroup (Foo a) where\n  (\u003c\u003e) = gmappend\n```\n\nThis library also synergizes with the `DerivingVia` extension\n(introduced in GHC 8.6), thanks to the `Generically` newtype.\n\n```haskell\ndata Foo a = Bar [a] [a]\n  deriving Generic\n  deriving Semigroup via (Generically (Foo a))\n```\n\nThese examples can be found in `test/example.hs`.\n\n---\n\nNote for completeness, the first example uses the following extensions and\nimports:\n\n```haskell\n{-# LANGUAGE DeriveGeneric #-}\n\n-- base\nimport Data.Semigroup (Semigroup(..))\n\n-- generic-data\nimport Generic.Data (Generic, gmappend)\nimport Generic.Data.Orphans ()\n```\n\nThe second example makes these additions on top:\n\n```haskell\n{-# LANGUAGE\n    DerivingStrategies,\n    DerivingVia #-}  -- since GHC 8.6.1\n\n-- In addition to the previous imports\nimport Generic.Data (Generically(..))\n```\n\n### Supported classes\n\nSupported classes that GHC currently can't derive: `Semigroup`, `Monoid`,\n`Applicative`, `Alternative`, `Eq1`, `Ord1`, `Show1`.\n\nOther classes from base are also supported, even though GHC can already derive\nthem:\n\n- `Eq`, `Ord`, `Enum`, `Bounded`, `Show`, `Read` (derivable by the standard);\n- `Functor`, `Foldable`, `Traversable` (derivable via extensions,\n  `DeriveFunctor`, etc.).\n\nTo derive type classes outside of the standard library, it might be worth\ntaking a look at [one-liner](https://hackage.haskell.org/package/one-liner).\n\n## Type metadata\n\nExtract type names, constructor names, number and arities of constructors, etc..\n\n## Type surgery\n\ngeneric-data offers simple operations (microsurgeries) on generic\nrepresentations.\n\nMore surgeries can be found in\n[generic-data-surgery](https://hackage.haskell.org/package/generic-data-surgery),\nand suprisingly, in\n[generic-lens](https://hackage.haskell.org/package/generic-lens) and\n[one-liner](https://hackage.haskell.org/package/one-liner).\n\nFor more details, see also:\n\n- the module `Generic.Data.Microsurgery`;\n\n- the files `test/lens-surgery.hs` and `one-liner-surgery.hs`.\n\n### Surgery example\n\nDerive an instance of `Show` generically for a record type,\nbut as if it were not a record.\n\n```haskell\n{-# LANGUAGE DeriveGeneric #-}\nimport Generic.Data (Generic, gshowsPrec)\nimport Generic.Data.Microsurgery (toData, derecordify)\n\n-- An example record type\nnewtype T = T { unT :: Int } deriving Generic\n\n-- Naively deriving Show would result in this being shown:\n--\n-- show (T 3) = \"T {unT = 3}\"\n--\n-- But instead, with a simple surgery, unrecordify, we can forget T was\n-- declared as a record:\n--\n-- show (T 3) = \"T 3\"\n\ninstance Show T where\n  showsPrec n = gshowsPrec n . derecordify . toData\n\n-- This example can be found in test/microsurgery.hs\n```\n\nAlternatively, using `DerivingVia`:\n\n```haskell\n{-# LANGUAGE DeriveGeneric, DerivingVia #-}\nimport Generic.Data (Generic)  -- Reexported from GHC.Generics\n\n-- Constructors must be visible to use DerivingVia\nimport Generic.Data.Microsurgery (Surgery, Surgery'(..), Generically(..), Derecordify)\n\ndata V = V { v1 :: Int, v2 :: Int }\n  deriving Generic\n  deriving Show via (Surgery Derecordify V)\n\n-- show (V {v1 = 3, v2 = 4}) = \"V 3 4\"\n```\n\n---\n\n## Related links\n\ngeneric-data aims to subsume generic deriving features of the following\npackages:\n\n- [semigroups](https://hackage.haskell.org/package/semigroups): generic\n  `Semigroup`, `Monoid`, but with a heavier dependency footprint.\n- [transformers-compat](https://hackage.haskell.org/package/transformers-compat):\n  generic `Eq1`, `Ord1`, `Show1`.\n- [generic-deriving](https://hackage.haskell.org/package/generic-deriving):\n  doesn't derive the classes in base (defines clones of these classes as a toy\n  example); has Template Haskell code to derive `Generic` (not in generic-data).\n\nOther relevant links.\n\n- [deriving-compat](https://hackage.haskell.org/package/deriving-compat):\n  deriving with Template Haskell.\n- [one-liner](https://hackage.haskell.org/package/one-liner): another approach\n  to using `GHC.Generics` to derive instances of many type classes, including\n  but not restricted to the above classes (this is done in\n  [one-liner-instances](https://hackage.haskell.org/package/one-liner-instances)).\n- [singletons](https://hackage.haskell.org/package/singletons),\n  [first-class-families](https://hackage.haskell.org/package/first-class-families)\n  (second one written by me)\n  libraries for dependently-typed programming in Haskell.\n- [coercible-utils](https://hackage.haskell.org/package/coercible-utils):\n  utilities for coercible types.\n\n---\n\n## Internal module policy\n\nModules under `Generic.Data.Internal` are not subject to any versioning policy.\nBreaking changes may apply to them at any time.\n\nIf something in those modules seems useful, please report it or create a pull\nrequest to export it from an external module.\n\n---\n\nAll contributions are welcome. Open an issue or a pull request on Github!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysxia%2Fgeneric-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flysxia%2Fgeneric-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysxia%2Fgeneric-data/lists"}