Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides Template Haskell functions for automatically generating
effect operation functions (that is, functions that use send
) from a given
effect algebra. For example, using the FileSystem
effect from the example in
the module documentation for Polysemy, we can write the following:
data FileSystem m a where ReadFile ::FilePath
-> FileSystemString
WriteFile ::FilePath
->String
-> FileSystem ()makeSemantic
''FileSystem
This will automatically generate the following functions:
readFile ::Member
FileSystem r =>FilePath
->Semantic
rString
readFile a =send
(ReadFile a) writeFile ::Member
FileSystem r =>FilePath
->String
->Semantic
r () writeFile a b =send
(WriteFile a b)
Synopsis
- makeSemantic :: Name -> Q [Dec]
- makeSemantic_ :: Name -> Q [Dec]
Documentation
makeSemantic :: Name -> Q [Dec] Source #
If T
is a GADT representing an effect algebra, as described in the module
documentation for Polysemy, $(
automatically
generates a smart constructor for every data constructor of makeSemantic
''T)T
.
makeSemantic_ :: Name -> Q [Dec] Source #
Like makeSemantic
, but does not provide type signatures. This can be used
to attach Haddock comments to individual arguments for each generated
function.
data Lang m a where Output :: String -> Lang () makeSemantic_ ''Lang -- | Output a string. output :: Member Lang r => String -- ^ String to output. -> Semantic r () -- ^ No result.
Note that makeEffect_
must be used before the explicit type signatures.