Copyright | (c) 2021 Xy Ren |
---|---|

License | BSD3 |

Maintainer | xy.r@outlook.com |

Stability | unstable |

Portability | non-portable (GHC only) |

Safe Haskell | None |

Language | Haskell2010 |

This module contains Template Haskell functions for generating definitions of functions that send effect operations. You mostly won't want to import this module directly; The Cleff module reexports the main functionalities of this module.

**This is an internal module and its API may change even between minor versions.** Therefore you should be
extra careful if you're to depend on this module.

## Synopsis

- makeEffect :: Name -> Q [Dec]
- makeEffect_ :: Name -> Q [Dec]

# Documentation

makeEffect :: Name -> Q [Dec] Source #

For a datatype `T`

representing an effect,

generates functions defintions for performing the
operations of `makeEffect`

T`T`

via `send`

. The naming rule is changing the first uppercase letter in the constructor name to
lowercase or removing the `:`

symbol in the case of operator constructors. Also, this function will preserve any
fixity declarations defined on the constructors.

Because of the limitations of Template Haskell, all constructors of `T`

should be *polymorphic in the monad type*,
if they are to be used by `makeEffect`

. For example, this is not OK:

data Limited ::`Effect`

where Noop :: Limited (`Eff`

es) ()

because the monad type

is not a fully polymorphic type variable.`Eff`

es

This function is also "weaker" than `polysemy`

's `makeSem`

, because this function cannot properly handle some
cases involving complex higher order effects. Those cases are rare, though. See the tests for more details.

makeEffect_ :: Name -> Q [Dec] Source #

Like `makeEffect`

, but doesn't generate type signatures. This is useful when you want to attach Haddock
documentation to the function signature, *e.g.*:

data Identity ::`Effect`

where Noop :: Identity m ()`makeEffect_`

''Identity -- | Perform nothing at all. noop :: Identity`:>`

es =>`Eff`

es ()

Be careful that the function signatures must be added *after* the `makeEffect_`

call.