Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines a state monad which allows the compiler's state (see FreeC.Environment) to be passed implicitly through the converter.
There are also utility functions to modify the state and retrieve information stored in the state.
Synopsis
- type Converter = ConverterT Identity
- runConverter :: Converter a -> Environment -> Reporter (a, Environment)
- evalConverter :: Converter a -> Environment -> Reporter a
- execConverter :: Converter a -> Environment -> Reporter Environment
- data ConverterT m a
- runConverterT :: Monad m => ConverterT m a -> Environment -> ReporterT m (a, Environment)
- evalConverterT :: Monad m => ConverterT m a -> Environment -> ReporterT m a
- execConverterT :: Monad m => ConverterT m a -> Environment -> ReporterT m Environment
- lift :: (MonadTrans t, Monad m) => m a -> t m a
- lift' :: Monad m => ReporterT m a -> ConverterT m a
- hoist :: (Hoistable t, Monad m) => t Identity a -> t m a
- type ConverterIO = ConverterT IO
- class Monad m => MonadConverter m where
- liftConverter :: Converter a -> m a
- getEnv :: MonadConverter m => m Environment
- inEnv :: MonadConverter m => (Environment -> a) -> m a
- putEnv :: MonadConverter m => Environment -> m ()
- modifyEnv :: MonadConverter m => (Environment -> Environment) -> m ()
- modifyEnv' :: MonadConverter m => (Environment -> (a, Environment)) -> m a
- localEnv :: MonadConverter m => m a -> m a
- moduleEnv :: MonadConverter m => m a -> m a
- shadowVarPats :: MonadConverter m => [VarPat] -> m a -> m a
State Monad
type Converter = ConverterT Identity Source #
Type synonym for the state monad used by the converter.
All converter functions usually require the current Environment
to perform the conversion. This monad allows these functions to
pass the environment around implicitly.
Additionally the converter can report error messages and warnings to the user if there is a problem while converting.
runConverter :: Converter a -> Environment -> Reporter (a, Environment) Source #
Runs the converter with the given initial environment and returns the converter's result as well as the final environment.
evalConverter :: Converter a -> Environment -> Reporter a Source #
Runs the converter with the given initial environment and returns the converter's result.
execConverter :: Converter a -> Environment -> Reporter Environment Source #
Runs the converter with the given initial environment and returns the final environment.
State Monad Transformer
data ConverterT m a Source #
A state monad used by the converter parameterized by the inner monad m
.
Instances
runConverterT :: Monad m => ConverterT m a -> Environment -> ReporterT m (a, Environment) Source #
Runs the converter with the given initial environment and returns the converter's result as well as the final environment.
evalConverterT :: Monad m => ConverterT m a -> Environment -> ReporterT m a Source #
Runs the converter with the given initial environment and returns the converter's result.
execConverterT :: Monad m => ConverterT m a -> Environment -> ReporterT m Environment Source #
Runs the converter with the given initial environment and returns the final environment.
lift :: (MonadTrans t, Monad m) => m a -> t m a Source #
Lift a computation from the argument monad to the constructed monad.
hoist :: (Hoistable t, Monad m) => t Identity a -> t m a Source #
Lifts the transformed identity monad to any transformed monad.
Using IO Actions in Converters
type ConverterIO = ConverterT IO Source #
A converter with an IO action as its inner monad.
Modifying Environments
class Monad m => MonadConverter m where Source #
Type class for monad a converter can be lifted to. Inside such monads, the functions for modifying the converters environment can be called without lifting them explicitly.
liftConverter :: Converter a -> m a Source #
Instances
Monad m => MonadConverter (ConverterT m) Source # | Converters can be lifted to arbitrary converter transformers. |
Defined in FreeC.Monad.Converter liftConverter :: Converter a -> ConverterT m a Source # |
getEnv :: MonadConverter m => m Environment Source #
Gets the current environment.
inEnv :: MonadConverter m => (Environment -> a) -> m a Source #
Gets a specific component of the current environment using the given function to extract the value from the environment.
putEnv :: MonadConverter m => Environment -> m () Source #
Sets the current environment.
modifyEnv :: MonadConverter m => (Environment -> Environment) -> m () Source #
Applies the given function to the environment.
modifyEnv' :: MonadConverter m => (Environment -> (a, Environment)) -> m a Source #
Gets a specific component and modifies the environment.
Encapsulating Environments
localEnv :: MonadConverter m => m a -> m a Source #
Runs the given converter and returns its result but discards all modifications to the environment.
moduleEnv :: MonadConverter m => m a -> m a Source #
Like localEnv
but modules that are added to the environment are still
available afterwards.
shadowVarPats :: MonadConverter m => [VarPat] -> m a -> m a Source #
Adds entries for variable patterns during the execution of the given converter.
Unlike localEnv
, all modifications to the environment are kept
(except for added entries), except for the definition of the variables.