From 192367da0be71ec528912b364bb718744ad7c9a9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 25 Apr 2018 09:58:21 -0400 Subject: [PATCH] Extract a runFresh helper. --- src/Control/Effect/Fresh.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Control/Effect/Fresh.hs b/src/Control/Effect/Fresh.hs index 6be171dea..dbdf9baa8 100644 --- a/src/Control/Effect/Fresh.hs +++ b/src/Control/Effect/Fresh.hs @@ -19,9 +19,11 @@ fresh = raise (send Fresh) reset :: (Effectful m, Member Fresh effects) => Int -> m effects () reset = raise . send . Reset +runFresh :: Eff (Fresh ': effects) a -> Eff effects a +runFresh = relayState (0 :: Int) (const pure) (\ s action k -> case action of + Fresh -> k (succ s) s + Reset s' -> k s' ()) -- | 'Fresh' effects are interpreted starting from 0, incrementing the current name with each request for a fresh name, and overwriting the counter on reset. instance RunEffect Fresh a where - runEffect = relayState (0 :: Int) (const pure) (\ s action k -> case action of - Fresh -> k (succ s) s - Reset s' -> k s' ()) + runEffect = runFresh