first-class-families: First class type families

[ library, mit, other ] [ Propose Tags ]

First class type families, eval-style defunctionalization

See Fcf.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

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.13) [details]
License MIT
Copyright 2018 Li-yao Xia
Author Li-yao Xia
Maintainer lysxia@gmail.com
Revised Revision 1 made by lyxia at 2019-01-11T10:55:09Z
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 2018-12-30T15:57:10Z
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 2018-12-30 [all 1 reports]

Readme for first-class-families-0.4.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, 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 passed to higher-order fcfs.

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!