{"id":16315713,"url":"https://github.com/chris-martin/multi-instance","last_synced_at":"2025-10-30T00:37:20.565Z","repository":{"id":56847639,"uuid":"104303147","full_name":"chris-martin/multi-instance","owner":"chris-martin","description":"Multiple typeclass instances, selected by explicit application of a phantom type parameter","archived":false,"fork":false,"pushed_at":"2022-03-15T20:12:50.000Z","size":27,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-31T09:22:39.744Z","etag":null,"topics":["haskell-library","monoid","phantom-types","semigroup"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/multi-instance","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chris-martin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-21T04:53:36.000Z","updated_at":"2022-03-15T19:45:43.000Z","dependencies_parsed_at":"2022-09-09T09:11:31.770Z","dependency_job_id":null,"html_url":"https://github.com/chris-martin/multi-instance","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chris-martin%2Fmulti-instance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chris-martin%2Fmulti-instance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chris-martin%2Fmulti-instance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chris-martin%2Fmulti-instance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chris-martin","download_url":"https://codeload.github.com/chris-martin/multi-instance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238183528,"owners_count":19430137,"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":["haskell-library","monoid","phantom-types","semigroup"],"created_at":"2024-10-10T21:58:16.847Z","updated_at":"2025-10-25T17:30:21.937Z","avatar_url":"https://github.com/chris-martin.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# multi-instance\n\n[![](https://travis-ci.org/chris-martin/multi-instance.svg)](https://travis-ci.org/chris-martin/multi-instance)\n\nAlternative versions of common typeclasses, augmented with a phantom type\nparameter `x`. The purpose of this is to deal with the case where a type has\nmore than one candidate instance for the original, unaugmented class.\n\n## Example: Integer sum and product\n\nThe canonical example of this predicament is selecting the monoid instance for a\ntype which forms a ring (and thus has at least two strong candidates for\nselection as *the* monoid), such as `Integer`. This therefore gives rise to the\n`Sum` and `Product` newtype wrappers, corresponding to the additive and\nmultiplicative monoids respectively.\n\nThe traditional `fold`-based summation of a list of integers looks like this:\n\n```haskell\n\u003e\u003e\u003e import Data.Foldable (fold)\n\u003e\u003e\u003e import Data.Monoid (Sum (..))\n\u003e\u003e\u003e getSum (fold [Sum 2, Sum 3, Sum 5]) :: Integer\n10\n```\n\nBy replacing `fold` with `multi'fold`, whose constraint is `MultiMonoid` rather\nthan `Data.Monoid.Monoid`, we can write the same thing without the newtype\nwrapper:\n\n```haskell\n\u003e\u003e\u003e :set -XFlexibleContexts -XTypeApplications\n\u003e\u003e\u003e multi'fold @Addition [2, 3, 5] :: Integer\n10\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchris-martin%2Fmulti-instance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchris-martin%2Fmulti-instance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchris-martin%2Fmulti-instance/lists"}