freer-simple-1.2.1.2: A friendly effect system for Haskell.
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Freer.TH

Description

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 Control.Monad.Freer, we can write the following:

data FileSystem r where
  ReadFile :: FilePath -> FileSystem String
  WriteFile :: FilePath -> String -> FileSystem ()
makeEffect ''FileSystem

This will automatically generate the following functions:

readFile :: Member FileSystem effs => FilePath -> Eff effs String
readFile a = send (ReadFile a)

writeFile :: Member FileSystem effs => FilePath -> String -> Eff effs ()
writeFile a b = send (WriteFile a b)
Synopsis

Documentation

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

If T is a GADT representing an effect algebra, as described in the module documentation for Control.Monad.Freer, $(makeEffect ''T) automatically generates a function that uses send with each operation. For more information, see the module documentation for Control.Monad.Freer.TH.

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

Like makeEffect, but does not provide type signatures. This can be used to attach Haddock comments to individual arguments for each generated function.

data Lang x where
  Output :: String -> Lang ()

makeEffect_ ''Lang

-- | Output a string.
output :: Member Lang effs
       => String    -- ^ String to output.
       -> Eff effs ()  -- ^ No result.

Note that makeEffect_ must be used before the explicit type signatures.