Hoogle Search
Within LTS Haskell 24.19 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
deriveGeneric :: Name -> Q [Dec]generics-sop Generics.SOP.TH Generate generics-sop boilerplate for the given datatype. This function takes the name of a datatype and generates:
- a Code instance
- a Generic instance
- a HasDatatypeInfo instance
data Tree = Leaf Int | Node Tree Tree
and sayderiveGeneric ''Tree
then you get code that is equivalent to:instance Generic Tree where type Code Tree = '[ '[Int], '[Tree, Tree] ] from (Leaf x) = SOP ( Z (I x :* Nil)) from (Node l r) = SOP (S (Z (I l :* I r :* Nil))) to (SOP (Z (I x :* Nil))) = Leaf x to (SOP (S (Z (I l :* I r :* Nil)))) = Node l r to (SOP (S (S x))) = x `seq` error "inaccessible" instance HasDatatypeInfo Tree where type DatatypeInfoOf Tree = T.ADT "Main" "Tree" '[ T.Constructor "Leaf", T.Constructor "Node" ] datatypeInfo _ = T.demoteDatatypeInfo (Proxy :: Proxy (DatatypeInfoOf Tree))
Limitations: Generation does not work for GADTs, for datatypes that involve existential quantification, for datatypes with unboxed fields.deriveGenericFunctions :: Name -> String -> String -> String -> Q [Dec]generics-sop Generics.SOP.TH Like deriveGenericOnly, but don't derive class instance, only functions. Example: If you say
deriveGenericFunctions ''Tree "TreeCode" "fromTree" "toTree"
then you get code that is equivalent to:type TreeCode = '[ '[Int], '[Tree, Tree] ] fromTree :: Tree -> SOP I TreeCode fromTree (Leaf x) = SOP ( Z (I x :* Nil)) fromTree (Node l r) = SOP (S (Z (I l :* I r :* Nil))) toTree :: SOP I TreeCode -> Tree toTree (SOP (Z (I x :* Nil))) = Leaf x toTree (SOP (S (Z (I l :* I r :* Nil)))) = Node l r toTree (SOP (S (S x))) = x `seq` error "inaccessible"
deriveGenericOnly :: Name -> Q [Dec]generics-sop Generics.SOP.TH Like deriveGeneric, but omit the HasDatatypeInfo instance.
deriveGenericOnlySubst :: Name -> (Name -> Q Type) -> Q [Dec]generics-sop Generics.SOP.TH Variant of deriveGenericOnly that allows to restrict the type parameters. Experimental function, exposed primarily for benchmarking.
deriveGenericSubst :: Name -> (Name -> Q Type) -> Q [Dec]generics-sop Generics.SOP.TH Variant of deriveGeneric that allows to restrict the type parameters. Experimental function, exposed primarily for benchmarking.
deriveMetadataType :: Name -> String -> Q [Dec]generics-sop Generics.SOP.TH Derive DatatypeInfo type for the type. Example: If you say
deriveMetadataType ''Tree "TreeDatatypeInfo"
then you get code that is equivalent to:type TreeDatatypeInfo = T.ADT "Main" "Tree" [ T.Constructor "Leaf", T.Constructor "Node" ]
deriveMetadataValue :: Name -> String -> String -> Q [Dec]generics-sop Generics.SOP.TH Deprecated: Use deriveMetadataType and demoteDatatypeInfo instead.
deriveInvariant :: Name -> Q [Dec]invariant Data.Functor.Invariant.TH Generates an Invariant instance declaration for the given data type or data family instance.
deriveInvariant2 :: Name -> Q [Dec]invariant Data.Functor.Invariant.TH Generates an Invariant2 instance declaration for the given data type or data family instance.
deriveInvariant2Options :: Options -> Name -> Q [Dec]invariant Data.Functor.Invariant.TH Like deriveInvariant2, but takes an Options argument.