bluefin-internal 0.0.4.0 → 0.0.4.2
raw patch · 4 files changed
+68/−1 lines, 4 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Bluefin.Internal: instance Bluefin.Internal.Handle (Bluefin.Internal.Reader r)
+ Bluefin.Internal.Examples: MkApplication :: (String -> Int -> Eff e [String]) -> State (Int, Bool) e -> Stream String e -> Application e
+ Bluefin.Internal.Examples: [applicationState] :: Application e -> State (Int, Bool) e
+ Bluefin.Internal.Examples: [logger] :: Application e -> Stream String e
+ Bluefin.Internal.Examples: [queryDatabase] :: Application e -> String -> Int -> Eff e [String]
+ Bluefin.Internal.Examples: data Application e
+ Bluefin.Internal.Examples: instance Bluefin.Internal.Handle Bluefin.Internal.Examples.Application
Files
- CHANGELOG.md +4/−0
- bluefin-internal.cabal +1/−1
- src/Bluefin/Internal.hs +42/−0
- src/Bluefin/Internal/Examples.hs +21/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+## 0.0.4.2++* Add documentation for `Handle`+ ## 0.0.4.0 * Add functions for compound effects
bluefin-internal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: bluefin-internal-version: 0.0.4.0+version: 0.0.4.2 license: MIT license-file: LICENSE author: Tom Ellis
src/Bluefin/Internal.hs view
@@ -199,7 +199,46 @@ -- @()@ and then yields values of type @a@. type Stream a = Coroutine a () +-- | You can define a @Handle@ instance for your compound handles. As+-- an example, an "application" handle with a dynamic effect for+-- database queries, a concrete effect for application state and a+-- concrete effect for a logging effect might look like this:+--+-- @+-- data Application e = MkApplication+-- { queryDatabase :: String -> Int -> Eff e [String],+-- applicationState :: State (Int, Bool) e,+-- logger :: Stream String e+-- }+-- @+--+-- To define @mapHandle@ for @Application@ you should apply+-- @mapHandle@ to all the fields that are themeselevs handles and+-- apply @useImpl@ to all the fields that are dynamic effects:+--+-- @+-- instance Handle Application where+-- mapHandle+-- MkApplication+-- { queryDatabase = q,+-- applicationState = a,+-- logger = l+-- } =+-- MkApplication+-- { queryDatabase = (fmap . fmap) useImpl q,+-- applicationState = mapHandle a,+-- logger = mapHandle l+-- }+-- @+--+-- Note that preceding @useImpl@ on the dynamic effect there is one+-- fmap per @->@ that appears in type of the dynamic effect. That is,+-- @queryDatabase@ has type @String -> Int -> Eff e [String]@, which+-- has two @->@, so there are two @fmap@s before @useImpl@.+ class Handle (h :: Effects -> Type) where+ -- | Used to create compound effects, i.e. handles that contain+ -- other handles. mapHandle :: (e :> es) => h e -> h es instance Handle (State s) where@@ -914,6 +953,9 @@ tell (Writer y) = yield y newtype Reader r (e :: Effects) = MkReader r++instance Handle (Reader r) where+ mapHandle (MkReader r) = MkReader r runReader :: -- | ͘
src/Bluefin/Internal/Examples.hs view
@@ -576,3 +576,24 @@ -- Left "/tmp/doesn't exist: openFile: does not exist (No such file or directory)" -- \$ cat /tmp/bluefin -- Hello!++-- instance Handle example++data Application e = MkApplication+ { queryDatabase :: String -> Int -> Eff e [String],+ applicationState :: State (Int, Bool) e,+ logger :: Stream String e+ }++instance Handle Application where+ mapHandle+ MkApplication+ { queryDatabase = q,+ applicationState = a,+ logger = l+ } =+ MkApplication+ { queryDatabase = (fmap . fmap) useImpl q,+ applicationState = mapHandle a,+ logger = mapHandle l+ }