free-compiler-0.3.0.0: A Haskell to Coq compiler.

Safe HaskellNone
LanguageHaskell2010

FreeC.Monad.Converter

Contents

Description

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

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
MonadTrans ConverterT Source # 
Instance details

Defined in FreeC.Monad.Converter

Methods

lift :: Monad m => m a -> ConverterT m a Source #

Hoistable ConverterT Source #

The converter monad can be lifted to any converter transformer.

Instance details

Defined in FreeC.Monad.Converter

Methods

hoist :: Monad m => ConverterT Identity a -> ConverterT m a Source #

Monad m => MonadState Environment (ConverterT m) Source # 
Instance details

Defined in FreeC.Monad.Converter

Monad m => Monad (ConverterT m) Source # 
Instance details

Defined in FreeC.Monad.Converter

Methods

(>>=) :: ConverterT m a -> (a -> ConverterT m b) -> ConverterT m b Source #

(>>) :: ConverterT m a -> ConverterT m b -> ConverterT m b Source #

return :: a -> ConverterT m a Source #

fail :: String -> ConverterT m a Source #

Monad m => Functor (ConverterT m) Source # 
Instance details

Defined in FreeC.Monad.Converter

Methods

fmap :: (a -> b) -> ConverterT m a -> ConverterT m b Source #

(<$) :: a -> ConverterT m b -> ConverterT m a Source #

Monad m => MonadFail (ConverterT m) Source #

Use MonadReporter to lift fail of Reporter to a ConverterT.

Instance details

Defined in FreeC.Monad.Converter

Methods

fail :: String -> ConverterT m a Source #

Monad m => Applicative (ConverterT m) Source # 
Instance details

Defined in FreeC.Monad.Converter

Methods

pure :: a -> ConverterT m a Source #

(<*>) :: ConverterT m (a -> b) -> ConverterT m a -> ConverterT m b Source #

liftA2 :: (a -> b -> c) -> ConverterT m a -> ConverterT m b -> ConverterT m c Source #

(*>) :: ConverterT m a -> ConverterT m b -> ConverterT m b Source #

(<*) :: ConverterT m a -> ConverterT m b -> ConverterT m a Source #

MonadIO m => MonadIO (ConverterT m) Source #

IO actions can be embedded into converters.

Instance details

Defined in FreeC.Monad.Converter

Methods

liftIO :: IO a -> ConverterT m a Source #

Monad m => MonadReporter (ConverterT m) Source #

Promotes a reporter to a converter that produces the same result and ignores the environment.

This type class instance allows report and reportFatal to be used directly in do-blocks of the Converter monad without explicitly lifting reporters.

Instance details

Defined in FreeC.Monad.Converter

Monad m => MonadConverter (ConverterT m) Source #

Converters can be lifted to arbitrary converter transformers.

Instance details

Defined in FreeC.Monad.Converter

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.

lift' :: Monad m => ReporterT m a -> ConverterT m a Source #

Converts a reporter to a converter.

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.

Methods

liftConverter :: Converter a -> m a Source #

Instances
Monad m => MonadConverter (ConverterT m) Source #

Converters can be lifted to arbitrary converter transformers.

Instance details

Defined in FreeC.Monad.Converter

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.