First-class type families
Go to file
gspia 6bf03f71c5 Add Take, Drop and Reverse functions
This commit adds the functions listed in the title.
The implementations follow the algorithms given in Data.List for
the corresponding term-level functions.
2020-01-08 16:54:08 +02:00
src Add Take, Drop and Reverse functions 2020-01-08 16:54:08 +02:00
test Implement suggestions 2019-09-13 21:58:19 +02:00
.travis.yml Regenerate .travis.yml with GHC-8.8.1 added 2019-08-30 00:12:28 +02:00
CHANGELOG.md CHANGELOG: Update 2019-09-15 09:08:19 -04:00
dev-stack.yaml Recommend copying dev-stack.yaml 2019-01-11 15:38:11 +01:00
first-class-families.cabal Bump to version 0.6.0.0 2019-09-15 09:09:11 -04:00
LICENSE First class type families 2018-07-09 00:13:46 -04:00
README.md Remove suggested sentence from readme 2020-01-06 13:22:07 +02: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!