| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Data.Recollections.TH
Collections generator
mkCollection :: Name -> Q [Dec] Source #
Generate a Collection a type from a enum-like type.
Every constructor is represented by a field.
Reserved words like type get a ' suffix.'
data Things = This | That
deriving (Eq, Ord, Show, Enum, Bounded)
mkCollection ''Things
-- resulting splice
data Collection a = { this, that :: a}
deriving (Eq, Show, Generic, Generic1, Functor, Foldable, Traversable)
deriving Applicative via (Generically1 Collection)mkIndices :: Name -> Q [Dec] Source #
Generate a value filled with the indices matching the fields.
indices :: Collection Things
indices = Collection { this = This, that = That }This is useful with the Applicative instance to provide indexed operations:
indexed c :: Collection a -> Collection (Things, a) indexed c = (,) <$> indices <*> c
Distributive
mkDistribute :: Name -> Q [Dec] Source #
Generate a dual of sequenceA.
distribute :: Functor f => f (Collection a) -> Collection (f a)
distribute f = Collection
{ this = this <$> f
, that = that <$> f
, something = something <$> f
, else' = else' <$> f
, entirely = entirely <$> f
}