mirror of
https://github.com/lexi-lambda/freer-simple.git
synced 2024-12-23 22:23:27 +03:00
Coding style
This commit is contained in:
parent
75db2ceb29
commit
01516e3d08
@ -10,13 +10,14 @@ import Control.Monad.Freer.Fresh (evalFresh, fresh)
|
||||
import Control.Monad.Freer.Trace (runTrace, trace)
|
||||
|
||||
|
||||
-- | Generate two fresh values.
|
||||
--
|
||||
-- >>> traceFresh
|
||||
-- Fresh 0
|
||||
-- Fresh 1
|
||||
traceFresh :: IO ()
|
||||
traceFresh = runTrace $ flip evalFresh 0 $ do
|
||||
n <- fresh
|
||||
trace $ "Fresh " <> show n
|
||||
n' <- fresh
|
||||
trace $ "Fresh " <> show n'
|
||||
{-
|
||||
Fresh 0
|
||||
Fresh 1
|
||||
-}
|
||||
n <- fresh
|
||||
trace $ "Fresh " <> show n
|
||||
n' <- fresh
|
||||
trace $ "Fresh " <> show n'
|
||||
|
@ -24,31 +24,30 @@ module Control.Monad.Freer.Fresh
|
||||
)
|
||||
where
|
||||
|
||||
import Prelude (($!), (+), (.), fst)
|
||||
import Prelude (($!), (+))
|
||||
|
||||
import Control.Applicative (pure, (<$>))
|
||||
import Control.Applicative (pure)
|
||||
import Data.Function ((.))
|
||||
import Data.Functor ((<$>))
|
||||
import Data.Int (Int)
|
||||
import Data.Tuple (fst)
|
||||
|
||||
import Control.Monad.Freer.Internal (Eff, Member, handleRelayS, send)
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Fresh --
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- | Fresh effect model.
|
||||
data Fresh a where
|
||||
Fresh :: Fresh Int
|
||||
Fresh :: Fresh Int
|
||||
|
||||
-- | Request a fresh effect.
|
||||
fresh :: Member Fresh effs => Eff effs Int
|
||||
fresh = send Fresh
|
||||
|
||||
-- | Handler for 'Fresh' effects, with an 'Int' for a starting value. The return
|
||||
-- value includes the next fresh value.
|
||||
-- | Handler for 'Fresh' effects, with an 'Int' for a starting value. The
|
||||
-- return value includes the next fresh value.
|
||||
runFresh :: Eff (Fresh ': effs) a -> Int -> Eff effs (a, Int)
|
||||
runFresh m s =
|
||||
handleRelayS s (\_s a -> pure (a, _s)) (\s' Fresh k -> (k $! s' + 1) s') m
|
||||
handleRelayS s (\s' a -> pure (a, s')) (\s' Fresh k -> (k $! s' + 1) s') m
|
||||
|
||||
-- | Handler for 'Fresh' effects, with an 'Int' for a starting value. Discards
|
||||
-- the next fresh value.
|
||||
|
Loading…
Reference in New Issue
Block a user