Polysemy: Introduction to Effect definition
In the first log we explained that in the expression:
displayFile path = do
trace $ "Displaying " <> path
content <- embed $ readFile path
embed $ putStr content
return $ length content
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:
trace a = emit $ 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.