Polysemy: Introduction to Effect definition
Gautier DI FOLCO December 07, 2022 [Haskell] #haskell #polysemy #design #effects systemsIn the first log we explained that in the expression:
= do
trace $ "Displaying " <> path
content <- embed $ readFile path
embed $ putStr content
return $ length content
displayFile path
trace
is emiting an effect of Trace
.
trace
has the following type:
and is generated via:
data Trace (m :: Type -> Type) a where
Trace :: String -> Trace m ()
makeSem ''Trace
makeSem
will generate something like:
= emit $ Trace a
trace a
So, whenever trace
is called, the value is sent to the interpreter.
Note: to keep it short m
will be replaced by Sem r
during interpretation
See the full the code here.