Polysemy: Design heuristics: IO huntingGautier DI FOLCO March 15, 2023 [Haskell] #haskell #polysemy #design #effects systems
When it come to designing effects, an efficient way to know where to start is to look for
IO (especially in
Let's have a look at a
= do embed $ putStrLn "Do stuff" embed $ threadDelay 250 embed $ putStrLn "Do even more stuff" actEmbed
We can reuse
Trace and introduce
Pause to improve it:
= do trace "Do stuff" pause 250 trace "Do even more stuff" actLifted
Way better, here's our effect and the default interpreter:
data Pause (m :: Type -> Type) a where Pause :: Int -> Pause m () makeSem ''Pause runPause = interpret $ \case Pause x -> embed $ threadDelay x
We can leverage our new effect with a new interpreter:
= interpret $ \case Pause x -> embed $ threadDelay $ n x runPauseAltered n
It will help us to change duration (reduce it in tests, increase it to debug, making it vary to see if something break).
See the full the code here.