first-class-families: First class type families

[ library, mit, other ] [ Propose Tags ]

First class type families, eval-style defunctionalization

See Fcf.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.0.1, 0.4.0.0, 0.5.0.0, 0.6.0.0, 0.7.0.0, 0.8.0.0, 0.8.0.1
Change log CHANGELOG.md
Dependencies base (>=4.9 && <4.14) [details]
License MIT
Copyright 2018 Li-yao Xia
Author Li-yao Xia
Maintainer lysxia@gmail.com
Category Other
Home page https://github.com/Lysxia/first-class-families#readme
Source repo head: git clone https://github.com/Lysxia/first-class-families
Uploaded by lyxia at 2020-01-30T20:10:47Z
Distributions Arch:0.8.0.1, Debian:0.8.0.0, LTSHaskell:0.8.0.1, NixOS:0.8.0.1, Stackage:0.8.0.1
Reverse Dependencies 26 direct, 120 indirect [details]
Downloads 12199 total (82 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-01-30 [all 1 reports]

Readme for first-class-families-0.7.0.0

[back to package description]

First-class type families Hackage Build Status

For example, consider this simple type family:

type family   FromMaybe (a :: k) (m :: Maybe k) :: k
type instance FromMaybe a 'Nothing  = a
type instance FromMaybe a ('Just b) = b

With first-class-families (fcfs), it translates to a data declaration and instances for a single Eval family:

import Fcf

data FromMaybe :: k -> Maybe k -> Exp k
type instance Eval (FromMaybe a 'Nothing)  = a
type instance Eval (FromMaybe a ('Just b)) = b

That way, the FromMaybe constructor can be partially applied, and passed to higher-order fcfs such as Map:

Eval (Map (FromMaybe 0) '[ 'Just 1, 'Nothing ])  =  '[ 1, 0 ] :: [Nat]

Essential language extensions:

{-# LANGUAGE
    DataKinds,
    PolyKinds,
    TypeFamilies,
    TypeInType,
    TypeOperators,
    UndecidableInstances #-}

See also

Haskell with only one type family (blogpost)


Contributions are welcome. Feel free to open an issue or make a PR on Github!