Safe Haskell | None |
---|---|
Language | Haskell98 |
If you have a data declaration which is a polymorphic product, for example
data Foo a b c = Foo a b c
or
data Foo a b c = Foo { foo :: a, bar :: b, baz :: c }
then you can use Template Haskell to automatically derive the
product-profunctor Default
instances and product-profunctor
"adaptor" with the following import and splice:
import Data.Profunctor.Product (p<n>) $(makeAdaptorAndInstance "pFoo" ''Foo)
- <n> is the number of fields in your record, so for Foo <n> would be 3.
- The adaptor for a type Foo is by convention called pFoo, but in practice you can call it anything.
Notice that currently the Template Haskell requires you import pn manually. This is because it is badly written and this restriction will go away in a future release.
The instance generated will be
instance (ProductProfunctor p, Default p a a', Default p b b', Default p c c') => Default p (Foo a b c) (Foo a' b' c')
and pFoo will have the type
pFoo :: ProductProfunctor p => Foo (p a a') (p b b') (p c c') -> p (Foo a b c) (Foo a' b' c')
Documentation
varNameOfBinder :: TyVarBndr -> Name Source
data MakeRecordT Source
MakeRecordT | |
|
makeRecordData :: MakeRecordT -> Q [Dec] Source
makeRecord :: MakeRecordT -> Q [Dec] Source
tupleAdaptors :: Int -> Name Source
mkTyVarsuffix :: String -> String -> TyVarBndr Source
mkTySuffix :: String -> String -> Type Source
mkVarTsuffix :: String -> String -> Type Source