mirror of
https://github.com/Lysxia/first-class-families.git
synced 2024-10-27 03:49:57 +03:00
First-class type families
src | ||
test | ||
.travis.yml | ||
CHANGELOG.md | ||
dev-stack.yaml | ||
first-class-families.cabal | ||
LICENSE | ||
README.md | ||
Setup.hs |
First-class type families
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!