From 01516e3d0808bbaaa80c7b1ce2681db682fdad75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Tr=C5=A1ko?= Date: Sat, 18 Mar 2017 12:18:10 +0100 Subject: [PATCH] Coding style --- examples/src/Fresh.hs | 17 +++++++++-------- src/Control/Monad/Freer/Fresh.hs | 19 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/src/Fresh.hs b/examples/src/Fresh.hs index a41e49b..ce787e5 100644 --- a/examples/src/Fresh.hs +++ b/examples/src/Fresh.hs @@ -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' diff --git a/src/Control/Monad/Freer/Fresh.hs b/src/Control/Monad/Freer/Fresh.hs index 0347e78..0585487 100644 --- a/src/Control/Monad/Freer/Fresh.hs +++ b/src/Control/Monad/Freer/Fresh.hs @@ -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.