bluefin-internal 0.0.2.0 → 0.0.3.0
raw patch · 3 files changed
+41/−72 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Bluefin.Internal.Examples: countExampleI :: IO ()
- Bluefin.Internal.Examples: evalStateI :: s -> (forall st. (?st :: State s st) => Eff (st :& es) a) -> Eff es a
- Bluefin.Internal.Examples: getI :: forall st s es. st :> es => (?st :: State s st) => Eff es s
- Bluefin.Internal.Examples: modifyI :: forall st s es. st :> es => (?st :: State s st) => (s -> s) -> Eff es ()
- Bluefin.Internal.Examples: throwI :: e1 :> es => (?ex :: Exception e e1) => e -> Eff es a
+ Bluefin.Internal: MkReader :: r -> Reader r (e :: Effects)
+ Bluefin.Internal: ask :: e :> es => Reader r e -> Eff es r
+ Bluefin.Internal: newtype Reader r (e :: Effects)
+ Bluefin.Internal: runReader :: r -> (forall e. Reader r e -> Eff (e :& es) a) -> Eff es a
+ Bluefin.Internal.Examples: incrementReadLine :: (e1 :> es, e2 :> es, e3 :> es) => State Int e1 -> Exception String e2 -> IOE e3 -> Eff es ()
+ Bluefin.Internal.Examples: runIncrementReadLine :: IO (Either String Int)
Files
- bluefin-internal.cabal +1/−1
- src/Bluefin/Internal.hs +16/−0
- src/Bluefin/Internal/Examples.hs +24/−71
bluefin-internal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: bluefin-internal-version: 0.0.2.0+version: 0.0.3.0 license: MIT license-file: LICENSE author: Tom Ellis
src/Bluefin/Internal.hs view
@@ -871,3 +871,19 @@ w -> Eff es () tell (Writer y) = yield y++newtype Reader r (e :: Effects) = MkReader r++runReader ::+ -- | ͘+ r ->+ (forall e. Reader r e -> Eff (e :& es) a) ->+ Eff es a+runReader r f = unsafeRemoveEff (f (MkReader r))++ask ::+ -- | ͘+ (e :> es) =>+ Reader r e ->+ Eff es r+ask (MkReader r) = pure r
src/Bluefin/Internal/Examples.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE NoMonoLocalBinds #-} {-# LANGUAGE NoMonomorphismRestriction #-}-{-# LANGUAGE ImplicitParams #-} module Bluefin.Internal.Examples where @@ -9,6 +8,7 @@ import Control.Monad.IO.Class (liftIO) import Data.Foldable (for_) import Data.Monoid (Any (Any, getAny))+import Text.Read (readMaybe) import Prelude hiding (break, drop, head, read, return) monadIOExample :: IO ()@@ -188,32 +188,6 @@ myInc h myBail h -throwI ::- (e1 :> es) =>- (?ex :: Exception e e1) =>- -- | Value to throw- e ->- Eff es a-throwI = throw ?ex--modifyI ::- forall st s es.- (st :> es) =>- (?st :: State s st) =>- -- | Apply this function to the state. The new value of the state- -- is forced before writing it to the state.- (s -> s) ->- Eff es ()-modifyI = modify ?st--getI ::- forall st s es.- (st :> es) =>- (?st :: State s st) =>- -- | The current value of the state- Eff es s-getI = get ?st- countExample :: IO () countExample = runEff $ \io -> do evalState @Int 0 $ \sn -> do@@ -252,50 +226,29 @@ get total --- welltypedwitch raised the intriguing possibility of using--- ImplicitParams to avoid having to pass effect handles explicitly.--- Unfortunately I've been snagged on two issues:------ 1. It doesn't seem possible to bind an implicit parameter in a--- lambda. (See--- https://discourse.haskell.org/t/why-cant-an-implicitparam-be-bound-by-a-lambda/8936/2)------ 2. Type inference gets stuck. I don't understand why.-countExampleI :: IO ()-countExampleI = runEff $ ((\io -> do- evalState @Int 0 $ ((\st -> do- let ?st = st- withJump $ \break -> forever $ do- n <- getI @st- when (n >= 10) (jumpTo break)- effIO io (print n)- modifyI @st (+ 1))- :: forall st. State Int st -> Eff (st :& e :& es) ()))- :: forall e es. IOE e -> Eff (e :& es) ())+incrementReadLine ::+ (e1 :> es, e2 :> es, e3 :> es) =>+ State Int e1 ->+ Exception String e2 ->+ IOE e3 ->+ Eff es ()+incrementReadLine state exception io = do+ withJump $ \break -> forever $ do+ line <- effIO io getLine+ i <- case readMaybe line of+ Nothing ->+ throw exception ("Couldn't read: " ++ line)+ Just i ->+ pure i --- We might want to resolve 1 by putting the ImplicitParam as an--- argument to the handler, but I can't work out how to get that to--- type check at all-evalStateI ::- -- | Initial state- s ->- -- | Stateful computation- (forall st. (?st :: State s st) => Eff (st :& es) a) ->- -- | Result- Eff es a-evalStateI s f = evalState s (\x -> let ?st = x in f)+ when (i == 0) $+ jumpTo break --- This just doesn't work. Have a made a silly mistake?+ modify state (+ i) -{--countExampleI2 :: IO ()-countExampleI2 = runEff $ ((\io -> do- evalStateI @Int 0 $ (do- withJump $ \break -> forever $ do- n <- getI @st- when (n >= 10) (jumpTo break)- effIO io (print n)- modifyI @st (+ 1))- :: forall st. (?st :: State Int st) => Eff (st :& e :& effes) ())- :: forall e effes. IOE e -> Eff (e :& effes) ())--}+runIncrementReadLine :: IO (Either String Int)+runIncrementReadLine = runEff $ \io -> do+ try $ \exception -> do+ ((), r) <- runState 0 $ \state -> do+ incrementReadLine state exception io+ pure r