registry 0.1.5.2 → 0.1.5.3
raw patch · 3 files changed
+71/−12 lines, 3 files
Files
- registry.cabal +2/−2
- src/Data/Registry/Make.hs +55/−10
- test/Test/Data/Registry/Make/SpecializationSpec.hs +14/−0
registry.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 3ee6a6cc26719b0cac6525924b2ae68ec4f80bdb946484f1df1db563ec513b52+-- hash: 981d12a883c0f677d0afbd378d66531a73851c8b2aa2e5b4ece20192a088dbc2 name: registry-version: 0.1.5.2+version: 0.1.5.3 synopsis: data structure for assembling components description: This library provides a "Registry" which is a data structure containing a list of functions and values representing dependencies in a directed acyclic graph. A `make` function can then be used to create a value of a specific type out of the registry. You can start with the [README](https://github.com/etorreborre/registry/blob/master/README.md) for a full description of the library.
src/Data/Registry/Make.hs view
@@ -59,7 +59,60 @@ -- | This version of make only execute checks at runtime -- this can speed-up compilation when writing tests or in ghci makeEither :: forall a ins out . (Typeable a) => Registry ins out -> Either Text a-makeEither registry =+makeEither = makeEitherWithContext (Context [someTypeRep (Proxy :: Proxy a)])++-- | This version of `make` only execute checks at runtime+-- this can speed-up compilation when writing tests or in ghci+makeUnsafe :: forall a ins out . (Typeable a) => Registry ins out -> a+makeUnsafe registry =+ case makeEither registry of+ Right a -> a+ Left e -> Prelude.error (toS e)++-- * SPECIALIZED VALUES++-- | make for specialized values+makeSpecialized :: forall a b ins out . (Typeable a, Typeable b, Contains b out, Solvable ins out) => Registry ins out -> b+makeSpecialized = makeSpecializedUnsafe @a @b++-- | make for specialized values+makeSpecializedPath :: forall path b ins out . (PathToTypeReps path, Typeable b, Contains b out, Solvable ins out) => Registry ins out -> b+makeSpecializedPath = makeSpecializedPathUnsafe @path @b++-- | makeFast for specialized values+makeSpecializedFast :: forall a b ins out . (Typeable a, Typeable b, Contains b out) => Registry ins out -> b+makeSpecializedFast = makeSpecializedUnsafe @a @b++-- | makeFast for specialized values+makeSpecializedPathFast :: forall path b ins out . (PathToTypeReps path, Typeable b, Contains b out) => Registry ins out -> b+makeSpecializedPathFast = makeSpecializedPathUnsafe @path @b++-- | makeUnsafe for specialized values+makeSpecializedUnsafe :: forall a b ins out . (Typeable a, Typeable b) => Registry ins out -> b+makeSpecializedUnsafe registry =+ case makeSpecializedEither @a @b registry of+ Right a -> a+ Left e -> Prelude.error (toS e)++-- | makeUnsafe for specialized values+makeSpecializedPathUnsafe :: forall path b ins out . (PathToTypeReps path, Typeable b) => Registry ins out -> b+makeSpecializedPathUnsafe registry =+ case makeSpecializedPathEither @path @b registry of+ Right a -> a+ Left e -> Prelude.error (toS e)++-- | makeEither for specialized values+makeSpecializedEither :: forall a b ins out . (Typeable a, Typeable b) => Registry ins out -> Either Text b+makeSpecializedEither = makeEitherWithContext (Context [someTypeRep (Proxy :: Proxy a), someTypeRep (Proxy :: Proxy b)])++-- | makeEither for specialized values+makeSpecializedPathEither :: forall path b ins out . (PathToTypeReps path, Typeable b) => Registry ins out -> Either Text b+makeSpecializedPathEither = makeEitherWithContext (Context (toList $ someTypeReps (Proxy :: Proxy path)))++-- | This version of make only execute checks at runtime+-- this can speed-up compilation when writing tests or in ghci+makeEitherWithContext :: forall a ins out . (Typeable a) => Context -> Registry ins out -> Either Text a+makeEitherWithContext context registry = let values = _values registry functions = _functions registry specializations = _specializations registry@@ -70,7 +123,7 @@ -- the list of values is kept as some State so that newly created values can be added to the current state case runStackWithValues values- (makeUntyped targetType (Context [targetType]) functions specializations modifiers)+ (makeUntyped targetType context functions specializations modifiers) of Left e ->@@ -84,11 +137,3 @@ Right (Just result) -> fromMaybe (Left $ "could not cast the computed value to a " <> show targetType <> ". The value is of type: " <> show (valueDynTypeRep result)) (Right <$> fromDynamic (valueDyn result))---- | This version of `make` only execute checks at runtime--- this can speed-up compilation when writing tests or in ghci-makeUnsafe :: forall a ins out . (Typeable a) => Registry ins out -> a-makeUnsafe registry =- case makeEither registry of- Right a -> a- Left e -> Prelude.error (toS e)
test/Test/Data/Registry/Make/SpecializationSpec.hs view
@@ -113,6 +113,7 @@ c2 === Config 2 c3 === Config 3 + data Base2 = Base2 { client1 :: Client1 , useConfig :: UseConfig@@ -233,3 +234,16 @@ +: funTo @IO InCommon +: funTo @IO SomeData +: end++test_make_specialized_values = test "specialized values can be made" $ do+ let r = val (Config 3)+ +: fun newUseConfig+ +: fun newClient1+ +: fun newClient2+ +: fun newBase2+ +: end+ let r' = specializePathVal @[Base2, Client1, UseConfig] (Config 1) .+ specializeVal @UseConfig (Config 2) $ r++ makeSpecialized @UseConfig r' === Config 2+ makeSpecializedPath @[Base2, Client1, UseConfig] r' === Config 1