First-class type families
Go to file
2020-03-01 15:41:52 -05:00
src Add note about Nat comparison 2020-03-01 15:41:52 -05:00
test Add doctests 2020-01-09 12:24:41 -05:00
.travis.yml Regenerate .travis.yml with GHC-8.8.1 added 2019-08-30 00:12:28 +02:00
CHANGELOG.md CHANGELOG: Update 2020-01-30 15:03:16 -05:00
dev-stack.yaml Recommend copying dev-stack.yaml 2019-01-11 15:38:11 +01:00
first-class-families.cabal Add Fcf.Class.Monoid and Fcf.Class.Ord 2020-03-01 15:41:52 -05:00
LICENSE First class type families 2018-07-09 00:13:46 -04:00
README.md README: Mention partial application 2020-01-06 05:10:58 -05:00
Setup.hs First class type families 2018-07-09 00:13:46 -04:00

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!