packages feed

dep-t 0.6.5.0 → 0.6.6.0

raw patch · 6 files changed

+158/−2 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Dep.Injects: class Injects r_ (m :: Type -> Type) (accum :: Type) | accum -> m
+ Dep.Injects: inject :: Injects r_ m accum => r_ m -> accum
+ Dep.Phases: (>>) :: Functor f => f x -> g y -> Compose f g y
+ Dep.Phases: (>>=) :: Functor f => f x -> (x -> g y) -> Compose f g y
+ Dep.Phases: Compose :: f (g a) -> Compose (f :: k -> Type) (g :: k1 -> k) (a :: k1)
+ Dep.Phases: [getCompose] :: Compose (f :: k -> Type) (g :: k1 -> k) (a :: k1) -> f (g a)
+ Dep.Phases: infixr 9 `Compose`
+ Dep.Phases: newtype Compose (f :: k -> Type) (g :: k1 -> k) (a :: k1)

Files

CHANGELOG.md view
@@ -1,5 +1,12 @@ # Revision history for dep-t ++## 0.6.6++* Added Dep.Phases. ++* Added Dep.Injects.+ ## 0.6.5  * Deprecated `Constructor`, `fixEnv` and the `Accum-` counterparts from `Dep.Env`.
dep-t.cabal view
@@ -1,7 +1,7 @@ cabal-version:       3.0  name:                dep-t-version:             0.6.5.0+version:             0.6.6.0 synopsis:            Dependency injection for records-of-functions. description:         Put all your functions in the environment record! Let all                      your functions read from the environment record! No favorites!@@ -27,9 +27,11 @@ library   import: common   exposed-modules:     Dep.Has+                       Dep.Injects                        Dep.Env                        Dep.Constructor                        Dep.Tagged+                       Dep.Phases                        Control.Monad.Dep                        Control.Monad.Dep.Class   hs-source-dirs:      lib 
lib/Dep/Has.hs view
@@ -103,7 +103,7 @@ -- The constraint can be used on its own, or with "Control.Monad.Dep.Class". type Has :: ((Type -> Type) -> Type) -> (Type -> Type) -> Type -> Constraint class Has r_ (m :: Type -> Type) (env :: Type) | env -> m where-  -- |  Given an environment @e@, produce a record-of-functions parameterized by the environment's effect monad @m@.+  -- |  Given an environment @env@, produce a record-of-functions parameterized by the environment's effect monad @m@.   --   -- The hope is that using a selector function on the resulting record will   -- fix the record's type without the need for type annotations.
+ lib/Dep/Injects.hs view
@@ -0,0 +1,43 @@+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DefaultSignatures #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE StandaloneKindSignatures #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE ImportQualifiedPost #-}+{-# LANGUAGE TypeOperators #-}++-- | Inject values into accumulators.+module Dep.Injects (+    -- * General-purpose injector.+    Injects (..)+    ) where++import Data.Kind+import GHC.Records+import GHC.TypeLits+import Data.Coerce++-- | Mirror image of 'Dep.Has.Has'.+--+-- Can be useful with 'Dep.Constructor.AccumConstructor' to register particular+-- monoidal values into a \"wider"\ monoidal value which is accumulated accross+-- all components.+type Injects :: ((Type -> Type) -> Type) -> (Type -> Type) -> Type -> Constraint+class Injects r_ (m :: Type -> Type) (accum :: Type) | accum -> m where+    -- | Given a value parameterized by the accumulator's effect monad @m@,+    -- produce an accumulator.+    inject :: r_ m -> accum++++
+ lib/Dep/Phases.hs view
@@ -0,0 +1,102 @@+module Dep.Phases (+    -- * Qualified do-notation for building phases+    -- $warning+    (>>=), +    (>>),+    -- * Re-exports+    Compose (..),+    ) where++import Data.Functor.Compose+import Prelude (Functor, (<$>), (<$))++(>>=) :: Functor f => f x -> (x -> g y) -> Compose f g y+f >>= k = Compose (k <$> f)++(>>) :: Functor f => f x -> g y -> Compose f g y+f >> g = Compose (g <$ f)++-- $warning+-- Convenient [qualified+-- do-notation](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/qualified_do.html#extension-QualifiedDo)+-- for defining nested applicative phases wrapped in 'Compose's.+-- +-- __BEWARE__! Despite its convenience, this do-notation lacks [many of the properties](https://wiki.haskell.org/Monad_laws#The_monad_laws_in_practice) +-- we tend to assume when working with do-notation. In particular, it's +-- NOT associative! This means that if we have +--+-- @+-- Dep.Phases.do    +--    somePhase+--    someOtherPhase+--    finalPhase+-- @+--+-- we CAN'T refactor to+--+-- @+-- Dep.Phases.do    +--    Dep.Phases.do +--      somePhase+--      someOtherPhase+--    finalPhase+-- @+--+-- It would indeed be useful (it would allow pre-packaging and sharing initial+-- phases as do-blocks) but it isn't supported.+--+-- __BEWARE__ #2! Do not use 'return' in this do-notation.+--+-- Some valid examples:+--+-- >>> :{+-- type Phases = (IO `Compose` IO `Compose` IO) Int+-- phases :: Phases+-- phases = Dep.Phases.do+--    r1 <- pure 1+--    r2 <- pure 2+--    pure $ r1 + r2+-- :}+--+--+-- >>> :{+-- type Phases = (IO `Compose` Maybe `Compose` Either Char) Int+-- phases :: Phases+-- phases = Dep.Phases.do+--    pure ()+--    Just 5+--    Left 'e'+-- :}+--+--+++-- $setup+--+-- >>> :set -XTypeApplications+-- >>> :set -XMultiParamTypeClasses+-- >>> :set -XImportQualifiedPost+-- >>> :set -XStandaloneKindSignatures+-- >>> :set -XNamedFieldPuns+-- >>> :set -XFunctionalDependencies+-- >>> :set -XFlexibleContexts+-- >>> :set -XDataKinds+-- >>> :set -XBlockArguments+-- >>> :set -XFlexibleInstances+-- >>> :set -XTypeFamilies+-- >>> :set -XDeriveGeneric+-- >>> :set -XViewPatterns+-- >>> :set -XDerivingStrategies+-- >>> :set -XDerivingVia+-- >>> :set -XDeriveAnyClass+-- >>> :set -XStandaloneDeriving+-- >>> :set -XUndecidableInstances+-- >>> :set -XTypeOperators+-- >>> :set -XScopedTypeVariables+-- >>> :set -XQualifiedDo+-- >>> :set -fno-warn-deprecations+-- >>> import Data.Kind+-- >>> import Data.Function ((&))+-- >>> import Dep.Env+-- >>> import GHC.Generics (Generic)+-- >>> import Prelude hiding ((>>=), (>>))
test/doctests.hs view
@@ -6,7 +6,9 @@     "lib/Control/Monad/Dep.hs",      "lib/Control/Monad/Dep/Class.hs",      "lib/Dep/Has.hs", +    "lib/Dep/Injects.hs",      "lib/Dep/Env.hs",+    "lib/Dep/Phases.hs",      "lib/Dep/Constructor.hs",     "lib/Dep/Tagged.hs"     ]