packages feed

boots 0.1 → 0.1.1

raw patch · 3 files changed

+66/−44 lines, 3 filesdep ~hspecPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: hspec

API changes (from Hackage documentation)

Files

README.md view
@@ -12,7 +12,7 @@  Simplify to create an application in Haskell. -When we decide to create an application using Haskell. We may need using configurations, loggers as basic functions. If this application needs storages, caches, etc., then we have to weaving the management of connection of these facilities into the application. Connections need to be created before and be destroyed after using them. There is a common strategy to manage connections, that is using `Control.Monad.Cont`. Then we can encapsulate the management of connections separately. For example, we can write a database plugin `Plugin cxt m DBConnection`, which can manage the database connections in monad `m` with context `cxt`. Context `cxt` may be requested for configurations or logging functions. When all the components of application are encapsulated by plugins, then building an application will be simplified.+When we decide to create an application using Haskell. We may need using configurations, loggers as basic functions. If this application needs storages, caches, etc., then we have to weaving the management of connection of these facilities into the application. Connections need to be created before and be destroyed after using them. There is a common strategy to manage connections, that is using `Control.Monad.Cont`. Then we can encapsulate the management of connections separately. For example, we can write a database factory `Factory m cxt DBConnection`, which can manage the database connections in monad `m` with context `cxt`. Context `cxt` may be requested for configurations or logging functions. When all the components of application are encapsulated by plugins, then building an application will be simplified.  ## A Project Use boots to Build 
boots.cabal view
@@ -1,50 +1,55 @@ cabal-version: 1.12-name: boots-version: 0.1-license: MIT-license-file: LICENSE-copyright: 2019 Daniel YU-maintainer: leptonyu@gmail.com-author: Daniel YU-homepage: https://github.com/leptonyu/boots#readme-synopsis: IoC Monad in Haskell-description:-    Inverse of control monad used in building large application.-category: Library, Application-build-type: Simple++-- This file has been generated from package.yaml by hpack version 0.31.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: 07ea4190e76748290f6abd6bd660c00f0d6ba2c91a51c3021fb010274bb510ac++name:           boots+version:        0.1.1+synopsis:       IoC Monad in Haskell+description:    Inverse of control monad used in building large application.+category:       Library, Application+homepage:       https://github.com/leptonyu/boots#readme+author:         Daniel YU+maintainer:     leptonyu@gmail.com+copyright:      2019 Daniel YU+license:        MIT+license-file:   LICENSE+build-type:     Simple extra-source-files:     README.md  library-    exposed-modules:-        Boots.Factory-    hs-source-dirs: src-    other-modules:-        Paths_boots-    default-language: Haskell2010-    default-extensions: FlexibleInstances MultiParamTypeClasses-                        GeneralizedNewtypeDeriving OverloadedStrings RecordWildCards-                        FlexibleContexts RankNTypes ScopedTypeVariables-    ghc-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures-    build-depends:-        base >=4.10 && <5,-        exceptions >=0.10.2 && <0.11,-        mtl >=2.2.2 && <2.3+  exposed-modules:+      Boots.Factory+  other-modules:+      Paths_boots+  hs-source-dirs:+      src+  default-extensions: FlexibleInstances MultiParamTypeClasses GeneralizedNewtypeDeriving OverloadedStrings RecordWildCards FlexibleContexts RankNTypes ScopedTypeVariables FunctionalDependencies ConstraintKinds+  ghc-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures+  build-depends:+      base >=4.10 && <5+    , exceptions >=0.10.2 && <0.11+    , mtl >=2.2.2 && <2.3+  default-language: Haskell2010  test-suite spec-    type: exitcode-stdio-1.0-    main-is: Spec.hs-    hs-source-dirs: test src-    other-modules:-        Boots.Factory-        Paths_boots-    default-language: Haskell2010-    default-extensions: FlexibleInstances MultiParamTypeClasses-                        GeneralizedNewtypeDeriving OverloadedStrings RecordWildCards-                        FlexibleContexts RankNTypes ScopedTypeVariables-    ghc-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures-    build-depends:-        base >=4.10 && <5,-        exceptions >=0.10.2 && <0.11,-        hspec ==2.*,-        mtl >=2.2.2 && <2.3+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Boots.Factory+      Paths_boots+  hs-source-dirs:+      test+      src+  default-extensions: FlexibleInstances MultiParamTypeClasses GeneralizedNewtypeDeriving OverloadedStrings RecordWildCards FlexibleContexts RankNTypes ScopedTypeVariables FunctionalDependencies ConstraintKinds+  ghc-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures+  build-depends:+      base >=4.10 && <5+    , exceptions >=0.10.2 && <0.11+    , hspec+    , mtl >=2.2.2 && <2.3+  default-language: Haskell2010
src/Boots/Factory.hs view
@@ -93,27 +93,35 @@   deriving (Functor, Applicative, Monad, MonadReader env, MonadIO)  instance MonadThrow m => MonadThrow (Factory m env) where+  {-# INLINE throwM #-}   throwM = offer . throwM  instance Monad m => MonadCont (Factory m env) where+  {-# INLINE callCC #-}   callCC a = do     env <- ask     wrap . running env $ callCC a  instance Semigroup (Factory m env env) where+  {-# INLINE (<>) #-}   a <> b = a >>= (`within` b)  instance Monoid (Factory m env env) where+  {-# INLINE mempty #-}   mempty = ask+  {-# INLINE mappend #-}   mappend = (<>)  instance C.Category (Factory m) where+  {-# INLINE id #-}   id  = ask+  {-# INLINE (.) #-}   a . b = b >>= (`within` a)  -- | Running the factory. running :: env -> Factory m env c -> (c -> m ()) -> m () running env pma = runContT (runReaderT (unFactory pma) env)+{-# INLINE running #-}  -- | Run the application using a specified factory. boot :: Monad m => Factory m () (m ()) -> m ()@@ -122,24 +130,29 @@ -- | Switch factory environment. withFactory :: (env' -> env) -> Factory m env component -> Factory m env' component withFactory = unsafeCoerce withReaderT+{-# INLINE withFactory #-}  -- | Construct factory under @env@, and adapt it to fit another @env'@. within :: env -> Factory m env component -> Factory m env' component within = withFactory . const+{-# INLINE within #-}  -- | Polish @component@ by a sequence of 'Factory', and construct a unified one. polish :: component -> [Factory m component component] -> Factory m env' component polish env = within env . mconcat+{-# INLINE polish #-}  -- | Nature transform of one 'Factory' with monad @n@ into another with monad @m@. natTrans :: (n () -> m ()) -> (m () -> n ()) -> Factory n env component -> Factory m env component natTrans fnm fmn fac = do   env <- ask   wrap $ \fm -> fnm $ running env fac (fmn . fm)+{-# INLINE natTrans #-}  -- | Wrap raw procedure into a 'Factory'. wrap :: ((c -> m ()) -> m ()) -> Factory m env c wrap = Factory . lift . ContT+{-# INLINE wrap #-}  -- | Construct open-close resource into a 'Factory'. bracket :: MonadCatch m => m res -> (res -> m ()) -> Factory m env res@@ -152,11 +165,15 @@     go (Left e) _ = throwM (e :: SomeException)     go _ (Left e) = throwM (e :: SomeException)     go _ _        = return ()+    {-# INLINE go #-}+{-# INLINE bracket #-}  -- | Lift a monad @m@ into a 'Factory'. offer :: Monad m => m a -> Factory m env a offer ma = wrap (ma >>=)+{-# INLINE offer #-}  -- | Put a delay action into 'Factory', it will run at close phase. delay :: MonadCatch m => m () -> Factory m env () delay ma = bracket (return ()) (const ma)+{-# INLINE delay #-}