Safe Haskell | None |
---|---|
Language | Haskell2010 |
Test.Goblin.TH
Description
Template Haskell derivation functions for the goblin-related typeclasses.
Synopsis
- deriveGoblin :: Name -> Q [Dec]
- deriveAddShrinks :: Name -> Q [Dec]
- deriveSeedGoblin :: Name -> Q [Dec]
Documentation
deriveGoblin :: Name -> Q [Dec] Source #
Derive a Goblin
instance for datatypes which have Goblin
and AddShrinks
instances for their enclosed fields.
tinker
s recursively with fields of a datatype, then uses <$$>
and <**>
to map the constructor over the tinkered fields.
conjure
s by using <$>
and <*>
over recursive calls to conjure
.
deriveGoblin ''(,) ======> instance (Goblin g a, AddShrinks a, Goblin g b, AddShrinks b) => Goblin g ((,) a b) where tinker gen = tinkerRummagedOrConjureOrSave ((( a b -> ((,) a) b) $$ tinker (( ((,) a _) -> a) $ gen)) ** tinker (( ((,) _ b) -> b) $ gen)) conjure = (saveInBagOfTricks =(((,) <$ conjure) * conjure))
deriveAddShrinks :: Name -> Q [Dec] Source #
Derive an AddShrinks
instance for datatypes which have AddShrinks
instances for their enclosed fields. Simply performs structural recursion
on fields, then uses <$>
and <*>
to apply the constructor over the
addShrinks
of the fields.
deriveAddShrinks ''(,) ======> instance (AddShrinks a, AddShrinks b) => AddShrinks ((,) a b) where addShrinks ((,) x y) = ((( x y -> ((,) x) y) $ addShrinks x) * addShrinks y)
deriveSeedGoblin :: Name -> Q [Dec] Source #
Derive a SeedGoblin
instance which calls saveInBagOfTricks
on the
argument then recurs structurally on fields.
deriveSeedGoblin ''(,) ======> instance (SeedGoblin a, Typeable a, SeedGoblin b, Typeable b) => SeedGoblin ((,) a b) where seeder p@((,) x y) = do (() <$ saveInBagOfTricks p) seeder x seeder y