packages feed

registry-hedgehog 0.1.1.0 → 0.1.1.1

raw patch · 2 files changed

+21/−8 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Data.Registry.Internal.TH: constructorName :: Con -> Q Text
+ Data.Registry.Internal.TH: constructorParameterName :: Con -> Q Name

Files

registry-hedgehog.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 43f24c96eca61918ac318573b5f30573358d5a979075a995f8c95a09c49ccf51+-- hash: d6259c5709d061f685f6bf9248c96be009efecfc81c474288825777d0b48c3b3  name:           registry-hedgehog-version:        0.1.1.0+version:        0.1.1.1 synopsis:       utilities to work with Hedgehog generators and `registry` description:    This library provides some functions to extract generators from a "Registry" and make stateful modifications of that Registry to precisely control the generation of data category:       Control
src/Data/Registry/Internal/TH.hs view
@@ -27,8 +27,9 @@     -- | Create a parameters for the selection function     parameterFor :: Name -> Con -> Q Pat     parameterFor typeName constructor = do+      constructorParam <- constructorParameterName constructor       constructorTag <- tagName constructor-      sigP (varP constructorTag) (appT (conT (mkName "GenIO")) (appT (appT (conT (mkName "Tag")) (litT (strTyLit (show constructorTag)))) (conT typeName)))+      sigP (varP constructorParam) (appT (conT (mkName "GenIO")) (appT (appT (conT (mkName "Tag")) (litT (strTyLit (show constructorTag)))) (conT typeName)))  -- Create a generator expression for a specific constructor of a data type -- runQ [|tag @"permanent" Permanent|]@@ -36,20 +37,32 @@ makeConstructorGenerator :: Con -> ExpQ makeConstructorGenerator constructor = do   constructorTag  <- tagName constructor-  constructorName <- nameOf constructor-  appE (appTypeE (varE (mkName "tag")) (litT (strTyLit (show constructorTag)))) (conE constructorName)+  constructorType <- nameOf constructor+  appE (appTypeE (varE (mkName "tag")) (litT (strTyLit (show constructorTag)))) (conE constructorType)  -- | Remove the tag of a given constructor: fmap unTag g :: GenIO (Tag "t" SomeType) -> GenIO SomeType untagGenerator :: Con -> ExpQ untagGenerator constructor = do-  constructorTag <- tagName constructor-  appE (appE (varE (mkName "fmap")) (varE (mkName "unTag"))) (varE constructorTag)+  constructorParam <- constructorParameterName constructor+  appE (appE (varE (mkName "fmap")) (varE (mkName "unTag"))) (varE constructorParam)  -- | Create a tag used to distinguish constructors in an ADT tagName :: Con -> Q Name tagName constructor = do+  name <- constructorName constructor+  pure $ mkName $ toS name++-- | Same as the tag name but lower cased+constructorParameterName :: Con -> Q Name+constructorParameterName constructor = do+  name <- constructorName constructor+  pure $ mkName (toS $ toLower name)++-- | Extract the last name of a constructor+constructorName :: Con -> Q Text+constructorName constructor = do   n <- nameOf constructor-  pure $ mkName $ toS . last . splitOn "." . toLower $ show n+  pure $ last . splitOn "." $ show n  -- | The name of a given constructor nameOf :: Con -> Q Name