registry 0.2.0.0 → 0.2.0.1
raw patch · 4 files changed
+36/−3 lines, 4 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Data.Registry.Registry: safeCoerce :: IsSameSet out out1 => Registry ins out -> Registry ins1 out1
+ Data.Registry.Solver: class IsSameSet (types1 :: [Type]) (types2 :: [Type])
+ Data.Registry.Solver: instance (ts1 GHC.Types.~ Data.Registry.Solver.Normalized types1, ts2 GHC.Types.~ Data.Registry.Solver.Normalized types2, Data.Registry.Solver.IsSubset ts1 ts2 (), Data.Registry.Solver.IsSubset ts1 ts2 ()) => Data.Registry.Solver.IsSameSet types1 types2
Files
- registry.cabal +2/−2
- src/Data/Registry/Registry.hs +6/−1
- src/Data/Registry/Solver.hs +6/−0
- test/Test/Data/Registry/Make/MakeSpec.hs +22/−0
registry.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 6557ba917c4e8ae98b72a5b1b743bccc3d26bef98070e9e3cb45e22a03cbc2a6+-- hash: af999eb6e06f804acbe70c38692e89b1b97d9dc204f6aecd3f2b716e224380f7 name: registry-version: 0.2.0.0+version: 0.2.0.1 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/Registry.hs view
@@ -153,9 +153,14 @@ data ERASED_TYPES + -- | In case it is hard to show that the types of 2 registries align -- for example with conditional like--- if True then fun myFunctionWithKnownInputs <: r else r+-- if True then fun myFunctionWithKnownOutputs <: r else r+safeCoerce :: (IsSameSet out out1) => Registry ins out -> Registry ins1 out1+safeCoerce (Registry a b c d) = Registry a b c d++-- | And for extreme cases where you know you're doing the right thing but can't prove it unsafeCoerce :: Registry ins out -> Registry ins1 out1 unsafeCoerce (Registry a b c d) = Registry a b c d
src/Data/Registry/Solver.hs view
@@ -52,6 +52,12 @@ instance IsSubset '[] out t instance (CanMake a out t, IsSubset els out t) => IsSubset (a ': els) out t +-- | Compute if each element of a list of types+-- is the same as another in a different order+class IsSameSet (types1 :: [Type]) (types2 :: [Type])++instance (ts1 ~ Normalized types1, ts2 ~ Normalized types2, IsSubset ts1 ts2 (), IsSubset ts1 ts2 ()) => IsSameSet types1 types2+ -- | Compute if a type is contained in a list of types type family Contains (a :: Type) (els :: [Type]) :: Constraint where Contains a els = Contains1 a els els
test/Test/Data/Registry/Make/MakeSpec.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE DataKinds #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-} module Test.Data.Registry.Make.MakeSpec where@@ -39,3 +40,24 @@ -- inverse of add1 (in terms of type signature) dda1 :: Text -> Int dda1 = T.length++-- test coerce+r1 = end+ <: fun dda1+ <: val ("" :: Text)++r2 :: Registry '[Text] '[Int, Text]+r2 = normalize $ end+ <: fun dda1+ <: val (1 :: Int)+ <: val ("" :: Text)++r3 :: Registry '[Text, Text, Text] '[Int, Int, Int, Text]+r3 = fun dda1 <: fun dda1 <: r2++r4 :: Registry '[Text, Text, Text] '[Int, Int, Int, Text]+r4 =+ if True then+ r3+ else+ safeCoerce r2