registry 0.1.6.3 → 0.1.7.0
raw patch · 10 files changed
+18/−34 lines, 10 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Registry.Lift: applyVariadic1 :: ApplyVariadic1 f a b => f a -> b
- Data.Registry.Lift: argsTo :: forall f a b. ApplyVariadic1 f a b => a -> b
- Data.Registry.Lift: class Monad f => ApplyVariadic1 f a b
- Data.Registry.Lift: instance (GHC.Base.Monad f, Data.Registry.Lift.ApplyVariadic1 f a' b', b Data.Type.Equality.~ (f a -> b')) => Data.Registry.Lift.ApplyVariadic1 f (a -> a') b
- Data.Registry.Lift: instance (GHC.Base.Monad f, b Data.Type.Equality.~ f a) => Data.Registry.Lift.ApplyVariadic1 f (f a) b
- Data.Registry.Registry: funAs :: forall m a b. (ApplyVariadic1 m a b, Typeable a, Typeable b) => a -> Typed b
+ Data.Registry.Lift: instance (GHC.Base.Monad f, b Data.Type.Equality.~ f a) => Data.Registry.Lift.ApplyVariadic f (f a) b
Files
- registry.cabal +2/−2
- src/Data/Registry/Lift.hs +3/−14
- src/Data/Registry/Registry.hs +0/−5
- test/Test/Data/Registry/Make/MakeSpec.hs +1/−1
- test/Test/Data/Registry/Make/MemoizeSpec.hs +6/−6
- test/Test/Data/Registry/MonadRandomSpec.hs +1/−1
- test/Test/Data/Registry/SmallExample.hs +2/−2
- test/Test/Data/Registry/THSpec.hs +1/−1
- test/Test/Tutorial/Exercise5.hs +1/−1
- test/Test/Tutorial/Exercise6.hs +1/−1
registry.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 5f0e4473870f2ef16f76783ea5f7c22baddb645e5b927eac9d2b80c68b2f1a25+-- hash: fcba2812a0ecc52110acade5e9fed0482c1c6ea5b50047c57cb08713dc4c9a42 name: registry-version: 0.1.6.3+version: 0.1.7.0 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/Lift.hs view
@@ -29,26 +29,15 @@ instance (Applicative f, b ~ f a) => ApplyVariadic f a b where applyVariadic = identity +instance (Monad f, b ~ f a) => ApplyVariadic f (f a) b where+ applyVariadic = join+ instance (Applicative f, ApplyVariadic f a' b', b ~ (f a -> b')) => ApplyVariadic f (a -> a') b where applyVariadic f fa = applyVariadic (f <*> fa) -- | Lift a pure function to effectful arguments and results allTo :: forall f a b. ApplyVariadic f a b => a -> b allTo a = (applyVariadic :: f a -> b) (pure a)---- | Typeclass for lifting impure functions to effectful arguments and results-class Monad f => ApplyVariadic1 f a b where- applyVariadic1 :: f a -> b--instance (Monad f, b ~ f a) => ApplyVariadic1 f (f a) b where- applyVariadic1 = join--instance (Monad f, ApplyVariadic1 f a' b', b ~ (f a -> b')) => ApplyVariadic1 f (a -> a') b where- applyVariadic1 f fa = applyVariadic1 (f <*> fa)---- | Lift an effectful function to effectful arguments and results-argsTo :: forall f a b . ApplyVariadic1 f a b => a -> b-argsTo a = (applyVariadic1 :: f a -> b) (pure a) -- | Typeclass for lifting a function with a result of type m b into a function -- with a result of type n b
src/Data/Registry/Registry.hs view
@@ -167,11 +167,6 @@ funTo :: forall m a b . (ApplyVariadic m a b, Typeable a, Typeable b) => a -> Typed b funTo a = fun (allTo @m a) --- | This is a shortcut to @fun . argsTo@ where @allTo@ lifts all the inputs--- to an Applicative context-funAs :: forall m a b . (ApplyVariadic1 m a b, Typeable a, Typeable b) => a -> Typed b-funAs a = fun (argsTo @m a)- -- | For a given type @a@ being currently built -- when a value of type @b@ is required pass a specific value specialize :: forall a b ins out . (Typeable a, Contains a out, Typeable b)
test/Test/Data/Registry/Make/MakeSpec.hs view
@@ -11,7 +11,7 @@ -- | Effectful creation with lifting test_lifted = test "functions can be lifted in order to participate in building instances" $ do f1 <- liftIO $- do let r = fun (argsTo @IO newF1)+ do let r = funTo @IO newF1 +: valTo @IO (1::Int) +: valTo @IO ("hey"::Text) +: end
test/Test/Data/Registry/Make/MemoizeSpec.hs view
@@ -16,9 +16,9 @@ counter <- newIORef 0 newSingOnce <- once (newSing counter)- let r = fun (argsTo @IO newC1)- +: fun (argsTo @IO newC2)- +: fun (argsTo @IO newSingOnce)+ let r = funTo @IO newC1+ +: funTo @IO newC2+ +: funTo @IO newSingOnce +: end c1 <- make @(IO C1) r c2 <- make @(IO C2) r@@ -32,9 +32,9 @@ do -- create a counter for the number of instantiations counter <- newIORef 0 - let r = fun (argsTo @IO newC1)- +: fun (argsTo @IO newC2)- +: fun (argsTo @IO (newSing counter))+ let r = funTo @IO newC1+ +: funTo @IO newC2+ +: funTo @IO (newSing counter) +: end r' <- memoize @IO @Sing r c1 <- make @(IO C1) r'
test/Test/Data/Registry/MonadRandomSpec.hs view
@@ -101,7 +101,7 @@ test_client_function_with_seeded_values = test "a function using MonadRandom can be executed with the RandomGenerator component and return predetermined values" $ do let registry' =- funAs @IO (newSeededRandomGenerator (RandomGeneratorConfig 1))+ funTo @IO (newSeededRandomGenerator (RandomGeneratorConfig 1)) +: registryProd client <- liftIO $ make @(IO Client) registry'
test/Test/Data/Registry/SmallExample.hs view
@@ -65,8 +65,8 @@ -- | Create a registry for all constructors registry =- funAs @IO (newS3 @IO)- +: funAs @IO (newApplication @IO)+ funTo @IO (newS3 @IO)+ +: funTo @IO (newApplication @IO) +: funTo @IO noLogging +: funTo @IO newLinesCounter +: valTo @IO (S3Config "bucket" "key")
test/Test/Data/Registry/THSpec.hs view
@@ -87,7 +87,7 @@ addIO0 _ = pure "" regIO0 :: Registry '[IO Int] '[IO Text, IO Int, IO Int]-regIO0 = funAs @IO addIO0 +: valTo @IO (1 :: Int) +: valTo @IO (2 :: Int) +: end+regIO0 = funTo @IO addIO0 +: valTo @IO (1 :: Int) +: valTo @IO (2 :: Int) +: end -- See the gory details of why this is necessary: https://gitlab.haskell.org/ghc/ghc/issues/9813 $(return [])
test/Test/Tutorial/Exercise5.hs view
@@ -32,7 +32,7 @@ +: funTo @IO newConsole +: funTo @IO newUserInput +: funTo @IO newRng- +: funAs @IO newCheckedSecretReader+ +: funTo @IO newCheckedSecretReader +: valTo @IO (SecretReaderConfig "txe/tests/Test/Tutorial/secret.txt") +: end
test/Test/Tutorial/Exercise6.hs view
@@ -24,7 +24,7 @@ +: funTo @IO newConsole +: funTo @IO newUserInput +: funTo @IO newRng- +: funAs @IO newCheckedSecretReader+ +: funTo @IO newCheckedSecretReader +: funTo @IO (tag @"unchecked" newSecretReader) +: valTo @IO (SecretReaderConfig "txe/tests/Test/Tutorial/secret.txt") +: end