Polysemy: Introduction to Effect interpretationGautier DI FOLCO December 11, 2022 [Haskell] #haskell #polysemy #design #effects systems
In my last log we defined the
data Trace (m :: Type -> Type) a where Trace :: String -> Trace m () makeSem ''Trace
One of the main interest of effects systems is to be able to define multiple interpretations for the same effects.
The simplest interpreter we can write is to drop simply the action:
= interpret $ \case Trace _ -> pure () ignoreTrace
interpret will "consume"
Note: we have a useful type alias
InterpreterFor for interpreters definitions.
Trace is simple enough to have a dropping interpreter, let's come with a more useful definition:
= interpret $ \case Trace m -> embed $ putStrLn m traceToStdout
We can also compose interpreters:
= traceToHandle stderr traceToHandle handle = interpret $ \case Trace m -> embed $ hPutStrLn handle m traceToStderr
See the full the code here.