registry 0.3.0.7 → 0.3.0.8
raw patch · 5 files changed
+62/−25 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Registry.Registry: instance (Data.Typeable.Internal.Typeable a, Data.Registry.Solver.IsSubset (Data.Registry.Solver.Inputs a) '[Data.Registry.Solver.Output b] a, Data.Registry.Solver.Inputs b GHC.Types.~ '[], Data.Typeable.Internal.Typeable b, insr GHC.Types.~ (Data.Registry.Solver.Inputs a Data.Registry.Solver.:++ (Data.Registry.Solver.Inputs b Data.Registry.Solver.:++ '[])), outr GHC.Types.~ '[Data.Registry.Solver.Output a, Data.Registry.Solver.Output b]) => Data.Registry.Registry.AddRegistryLike (Data.Registry.Internal.Types.Typed a) (Data.Registry.Internal.Types.Typed b) (Data.Registry.Registry.Registry insr outr)
- Data.Registry.Registry: instance (Data.Typeable.Internal.Typeable a, Data.Registry.Solver.IsSubset (Data.Registry.Solver.Inputs a) out2 a, insr GHC.Types.~ (Data.Registry.Solver.Inputs a Data.Registry.Solver.:++ ins2), outr GHC.Types.~ (Data.Registry.Solver.Output a : out2)) => Data.Registry.Registry.AddRegistryLike (Data.Registry.Registry.Registry ins2 out2) (Data.Registry.Internal.Types.Typed a) (Data.Registry.Registry.Registry insr outr)
- Data.Registry.Registry: instance (Data.Typeable.Internal.Typeable a, Data.Typeable.Internal.Typeable b, insr GHC.Types.~ (Data.Registry.Solver.Inputs a Data.Registry.Solver.:++ (Data.Registry.Solver.Inputs b Data.Registry.Solver.:++ '[])), outr GHC.Types.~ '[Data.Registry.Solver.Output a, Data.Registry.Solver.Output b]) => Data.Registry.Registry.AddRegistryUncheckedLike (Data.Registry.Internal.Types.Typed a) (Data.Registry.Internal.Types.Typed b) (Data.Registry.Registry.Registry insr outr)
- Data.Registry.Registry: instance (Data.Typeable.Internal.Typeable a, insr GHC.Types.~ (Data.Registry.Solver.Inputs a Data.Registry.Solver.:++ ins2), outr GHC.Types.~ (Data.Registry.Solver.Output a : out2)) => Data.Registry.Registry.AddRegistryUncheckedLike (Data.Registry.Registry.Registry ins2 out2) (Data.Registry.Internal.Types.Typed a) (Data.Registry.Registry.Registry insr outr)
+ Data.Registry.Registry: addTypedUnchecked :: (Typeable a, Typeable b, ins ~ (Inputs a :++ Inputs b), out ~ '[Output a, Output b]) => Typed a -> Typed b -> Registry ins out
+ Data.Registry.Registry: appendUnchecked :: Typeable a => Registry ins out -> Typed a -> Registry (ins :++ Inputs a) (out :++ '[Output a])
+ Data.Registry.Registry: instance (Data.Typeable.Internal.Typeable a, Data.Registry.Solver.IsSubset (Data.Registry.Solver.Inputs a) '[Data.Registry.Solver.Output b] a, Data.Typeable.Internal.Typeable b, insr GHC.Types.~ (Data.Registry.Solver.Inputs a Data.Registry.Solver.:++ Data.Registry.Solver.Inputs b), outr GHC.Types.~ '[Data.Registry.Solver.Output a, Data.Registry.Solver.Output b]) => Data.Registry.Registry.AddRegistryLike (Data.Registry.Internal.Types.Typed a) (Data.Registry.Internal.Types.Typed b) (Data.Registry.Registry.Registry insr outr)
+ Data.Registry.Registry: instance (Data.Typeable.Internal.Typeable a, Data.Registry.Solver.IsSubset (Data.Registry.Solver.Inputs a) out2 a, insr GHC.Types.~ (ins2 Data.Registry.Solver.:++ Data.Registry.Solver.Inputs a), outr GHC.Types.~ (out2 Data.Registry.Solver.:++ '[Data.Registry.Solver.Output a])) => Data.Registry.Registry.AddRegistryLike (Data.Registry.Registry.Registry ins2 out2) (Data.Registry.Internal.Types.Typed a) (Data.Registry.Registry.Registry insr outr)
+ Data.Registry.Registry: instance (Data.Typeable.Internal.Typeable a, Data.Typeable.Internal.Typeable b, insr GHC.Types.~ (Data.Registry.Solver.Inputs a Data.Registry.Solver.:++ Data.Registry.Solver.Inputs b), outr GHC.Types.~ '[Data.Registry.Solver.Output a, Data.Registry.Solver.Output b]) => Data.Registry.Registry.AddRegistryUncheckedLike (Data.Registry.Internal.Types.Typed a) (Data.Registry.Internal.Types.Typed b) (Data.Registry.Registry.Registry insr outr)
+ Data.Registry.Registry: instance (Data.Typeable.Internal.Typeable a, insr GHC.Types.~ (ins2 Data.Registry.Solver.:++ Data.Registry.Solver.Inputs a), outr GHC.Types.~ (out2 Data.Registry.Solver.:++ '[Data.Registry.Solver.Output a])) => Data.Registry.Registry.AddRegistryUncheckedLike (Data.Registry.Registry.Registry ins2 out2) (Data.Registry.Internal.Types.Typed a) (Data.Registry.Registry.Registry insr outr)
Files
- registry.cabal +2/−2
- src/Data/Registry/RIO.hs +1/−4
- src/Data/Registry/Registry.hs +26/−19
- src/Data/Registry/Solver.hs +3/−0
- test/Test/Data/Registry/RegistrySpec.hs +30/−0
registry.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: ae5e25537d62d420d9fa82531a22426aa1bd8507f6bff266176de9eda97dba39+-- hash: fa621a560c312bba02cbbb23e0bcdeb93cf048b5c69ea7d4405a73f9bbe77db8 name: registry-version: 0.3.0.7+version: 0.3.0.8 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/RIO.hs view
@@ -9,10 +9,7 @@ type RIO = ResourceT IO -- | This function must be used to run services involving a top component--- It creates the top component and invokes all warmup functions------ The passed function 'f' is used to decide whether to continue or--- not depending on the Result+-- It creates an application of type a and which can return a result of type b. -- -- We also make sure that all effects are memoized by calling `memoizeAll` on the Registry here! withRegistry ::
src/Data/Registry/Registry.hs view
@@ -102,25 +102,32 @@ -- Internally elements are stored as 'Dynamic' values -- The signature checks that a constructor of type 'a' can be fully -- constructed from elements of the registry before adding it-register ::- (Typeable a, IsSubset (Inputs a) out a) =>- Typed a ->- Registry ins out ->- Registry (Inputs a :++ ins) (Output a ': out)+register :: (Typeable a, IsSubset (Inputs a) out a) => Typed a -> Registry ins out -> Registry (Inputs a :++ ins) (Output a ': out) register = registerUnchecked -- | Store an element in the registry -- Internally elements are stored as 'Dynamic' values-registerUnchecked ::- (Typeable a) =>- Typed a ->- Registry ins out ->- Registry (Inputs a :++ ins) (Output a ': out)+registerUnchecked :: (Typeable a) => Typed a -> Registry ins out -> Registry (Inputs a :++ ins) (Output a ': out) registerUnchecked (TypedValue v) (Registry (Values vs) functions specializations modifiers) = Registry (Values (v : vs)) functions specializations modifiers registerUnchecked (TypedFunction f) (Registry (Values vs) (Functions fs) specializations modifiers) = Registry (Values vs) (Functions (f : fs)) specializations modifiers +-- | Store an element in the registry, at the end of the registry+-- Internally elements are stored as 'Dynamic' values+appendUnchecked :: (Typeable a) => Registry ins out -> Typed a -> Registry (ins :++ Inputs a) (out :++ '[Output a])+appendUnchecked (Registry (Values vs) functions specializations modifiers) (TypedValue v) =+ Registry (Values (vs <> [v])) functions specializations modifiers+appendUnchecked (Registry (Values vs) (Functions fs) specializations modifiers) (TypedFunction f) =+ Registry (Values vs) (Functions (fs <> [f])) specializations modifiers++-- | Add 2 typed values together to form an initial registry+addTypedUnchecked :: (Typeable a, Typeable b, ins ~ (Inputs a :++ Inputs b), out ~ ('[Output a, Output b])) => Typed a -> Typed b -> Registry ins out+addTypedUnchecked (TypedValue v1) (TypedValue v2) = Registry (Values [v1, v2]) mempty mempty mempty+addTypedUnchecked (TypedValue v1) (TypedFunction f2) = Registry (Values [v1]) (Functions [f2]) mempty mempty+addTypedUnchecked (TypedFunction f1) (TypedValue v2) = Registry (Values [v2]) (Functions [f1]) mempty mempty+addTypedUnchecked (TypedFunction f1) (TypedFunction f2) = Registry mempty (Functions [f1, f2]) mempty mempty+ -- | Add an element to the Registry but do not check that the inputs of 'a' -- can already be produced by the registry infixr 5 +:@@ -144,16 +151,16 @@ (<:) = register instance- (Typeable a, IsSubset (Inputs a) out2 a, insr ~ (Inputs a :++ ins2), outr ~ (Output a : out2)) =>+ (Typeable a, IsSubset (Inputs a) out2 a, insr ~ (ins2 :++ Inputs a), outr ~ (out2 :++ '[Output a])) => AddRegistryLike (Registry ins2 out2) (Typed a) (Registry insr outr) where- (<:) = flip register+ (<:) = appendUnchecked instance- (Typeable a, IsSubset (Inputs a) '[Output b] a, Inputs b ~ '[], Typeable b, insr ~ (Inputs a :++ (Inputs b :++ '[])), outr ~ (Output a : '[Output b])) =>+ (Typeable a, IsSubset (Inputs a) '[Output b] a, Typeable b, insr ~ (Inputs a :++ Inputs b), outr ~ (Output a : '[Output b])) => AddRegistryLike (Typed a) (Typed b) (Registry insr outr) where- (<:) a b = register a (register b end)+ (<:) a b = addTypedUnchecked a b -- Unchecked unification of +: and <+> infixr 5 <+@@ -171,16 +178,16 @@ (<+) = registerUnchecked instance- (Typeable a, insr ~ (Inputs a :++ ins2), outr ~ (Output a : out2)) =>+ (Typeable a, insr ~ (ins2 :++ Inputs a), outr ~ (out2 :++ '[Output a])) => AddRegistryUncheckedLike (Registry ins2 out2) (Typed a) (Registry insr outr) where- (<+) = flip registerUnchecked+ (<+) = appendUnchecked instance- (Typeable a, Typeable b, insr ~ (Inputs a :++ (Inputs b :++ '[])), outr ~ (Output a : '[Output b])) =>+ (Typeable a, Typeable b, insr ~ (Inputs a :++ Inputs b), outr ~ '[Output a, Output b]) => AddRegistryUncheckedLike (Typed a) (Typed b) (Registry insr outr) where- (<+) a b = registerUnchecked a (registerUnchecked b end)+ (<+) a b = addTypedUnchecked a b -- | Make the lists of types in the Registry unique, either for better display -- or for faster compile-time resolution with the make function@@ -207,7 +214,7 @@ -- | The empty Registry end :: Registry '[] '[]-end = Registry (Values []) (Functions []) (Specializations []) (Modifiers [])+end = Registry mempty mempty mempty mempty -- | Create a value which can be added to the 'Registry' val :: (Typeable a, Show a) => a -> Typed a
src/Data/Registry/Solver.hs view
@@ -51,6 +51,9 @@ instance IsSubset '[] out t +-- | The list of elements: a + els is a subset of out if els is a subset of out and+-- a is also included in the set out. The search for a in out is done via a+-- type family in order to be able to display an error message if it can't be found instance (CanMake a out t, IsSubset els out t) => IsSubset (a ': els) out t -- | Compute if each element of a list of types
test/Test/Data/Registry/RegistrySpec.hs view
@@ -22,6 +22,27 @@ result <- liftIO $ readIORef ref result === "hey" +test_append_values = test "2 values can be appended together" $ do+ let r = val (1 :: Int) <: val (2 :: Int)+ make @Int r === 1++ let r2 = val (1 :: Int) <+ val (2 :: Int)+ make @Int r2 === 1++test_append_value_to_registry = test "a value can be appended to a registry" $ do+ let r = (val (1 :: Int) <: val (2 :: Int)) <: val (3 :: Int)+ make @Int r === 1++ let r2 = (val (1 :: Int) <+ val (2 :: Int)) <+ val (3 :: Int)+ make @Int r2 === 1++test_prepend_value_to_registry = test "a value can be prepended to a registry" $ do+ let r = val (1 :: Int) <: (val (2 :: Int) <: val (3 :: Int))+ make @Int r === 1++ let r2 = val (1 :: Int) <+ (val (2 :: Int) <+ val (3 :: Int))+ make @Int r2 === 1+ -- * newtype Logger = Logger {info :: Text -> IO ()}@@ -45,6 +66,15 @@ <: (val ("t" :: Text) +: end) <: (val ("t" :: Text) +: end) <: val ("t" :: Text)++registry2 :: Registry '[] [Text, Text]+registry2 =+ val ("t" :: Text)+ <: val ("t" :: Text)++registry3 :: Registry '[] '[Int] =+ val (10 :: Int)+ <+ end -- * COMPILATION CHECK LIFTING (see #7)