{"id":15288111,"url":"https://github.com/lysxia/first-class-families","last_synced_at":"2025-04-07T06:11:56.785Z","repository":{"id":32699495,"uuid":"140229311","full_name":"Lysxia/first-class-families","owner":"Lysxia","description":"First-class type families","archived":false,"fork":false,"pushed_at":"2024-08-20T16:13:41.000Z","size":129,"stargazers_count":87,"open_issues_count":7,"forks_count":12,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-07T06:11:52.862Z","etag":null,"topics":["dependent-types","haskell","types"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/first-class-families","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-07-09T03:59:54.000Z","updated_at":"2025-02-11T20:34:02.000Z","dependencies_parsed_at":"2024-03-28T12:24:37.486Z","dependency_job_id":"71cd445d-0f5c-4f04-b80c-5e3b61a4b1a4","html_url":"https://github.com/Lysxia/first-class-families","commit_stats":{"total_commits":136,"total_committers":7,"mean_commits":"19.428571428571427","dds":"0.23529411764705888","last_synced_commit":"933c2527de9bfcb162e0eebcbcdac4f28a39bd3b"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Ffirst-class-families","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Ffirst-class-families/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Ffirst-class-families/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Ffirst-class-families/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lysxia","download_url":"https://codeload.github.com/Lysxia/first-class-families/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601448,"owners_count":20964864,"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":["dependent-types","haskell","types"],"created_at":"2024-09-30T15:44:09.624Z","updated_at":"2025-04-07T06:11:56.766Z","avatar_url":"https://github.com/Lysxia.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# First-class type families [![Hackage](https://img.shields.io/hackage/v/first-class-families.svg)](https://hackage.haskell.org/package/first-class-families) [![Build Status](https://travis-ci.org/Lysxia/first-class-families.svg)](https://travis-ci.org/Lysxia/first-class-families)\n\nFirst-class type families are type-level functions that can be\ncomposed using higher-order functions.\n\nThe core of the idea is an extensible kind of \"type-level expressions\"\nand an open type family for evaluating such expressions.\n\n```haskell\ntype Exp (k :: Type) :: Type\ntype family Eval (e :: Exp k) :: k\n```\n\nThis library provides that core foundation,\nand also exports basic first-class type families.\n\n## Example\n\nFor example, consider this simple type family:\n\n```haskell\ntype family   FromMaybe (a :: k) (m :: Maybe k) :: k\ntype instance FromMaybe a 'Nothing  = a\ntype instance FromMaybe a ('Just b) = b\n```\n\nWith first-class-families (fcfs), it translates to a `data` declaration\nand instances for a single `Eval` family:\n\n```haskell\nimport Fcf\n\ndata FromMaybe :: k -\u003e Maybe k -\u003e Exp k\ntype instance Eval (FromMaybe a 'Nothing)  = a\ntype instance Eval (FromMaybe a ('Just b)) = b\n```\n\nThat way, the `FromMaybe` constructor can be partially applied,\nand passed to higher-order fcfs such as `Map`:\n\n```haskell\nEval (Map (FromMaybe 0) '[ 'Just 1, 'Nothing ])  =  '[ 1, 0 ] :: [Nat]\n```\n\nEssential language extensions:\n\n```haskell\n{-# LANGUAGE\n    DataKinds,\n    PolyKinds,\n    TypeFamilies,\n    TypeInType,\n    TypeOperators,\n    UndecidableInstances #-}\n```\n\n## Overview\n\n- `Fcf.Core`: definition of `Exp` and `Eval`.\n- `Fcf.Combinators`: general combinators to compose first-class families.\n- `Fcf.Data.*`: first-class families on common data types.\n- `Fcf.Class.*`: overloaded first-class families.\n- `Fcf.Utils`: miscellaneous.\n\nThe top-level module `Fcf` is a prelude to get acquainted with the library.\nFor regular use, import what you need from the specialized modules\nabove, preferably with explicit import lists.\n\n```haskell\nimport Fcf                       -- Simple but fragile\n\nimport Fcf.Class.Functor (FMap)  -- Explicit and robust\n```\n\n## Features\n\n### Overloaded type families\n\nValue-level functions can be overloaded using type classes.\nType families---type-level functions---are open by design,\nso overloading is as easy as just declaring them with more general types.\n\n```haskell\ndata Map :: (a -\u003e Exp b) -\u003e f a -\u003e Exp (f b)\n\n-- Instances for f = []\ntype instance Eval (Map f '[]) = '[]\ntype instance Eval (Map f (x ': xs)) = Eval (f x) ': Eval (Map f xs)\n\n-- Instances for f = Maybe\ntype instance Eval (Map f 'Nothing) = 'Nothing\ntype instance Eval (Map f ('Just x)) = 'Just (Eval (f x))\n```\n\n## See also\n\n- [Haskell with only one type family](http://blog.poisson.chat/posts/2018-08-06-one-type-family.html)\n- [Overloaded type families](https://blog.poisson.chat/posts/2018-09-29-overloaded-families.html)\n- [The *singletons* library](https://hackage.haskell.org/package/singletons)\n\n---\n\nContributions are welcome. Feel free to open an issue or make a PR on\n[Github](https://github.com/Lysxia/first-class-families)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysxia%2Ffirst-class-families","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flysxia%2Ffirst-class-families","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysxia%2Ffirst-class-families/lists"}