Copyright | (c) 2010 2011 Simon Meier |
---|---|
License | GPL v3 (see LICENSE) |
Maintainer | Simon Meier <iridcode@gmail.com> |
Portability | GHC only |
Safe Haskell | None |
Language | Haskell98 |
Control.Monad.Fresh
Description
Computations that need a fresh name supply.
- class (Applicative m, Monad m) => MonadFresh m where
- type Fresh = FreshT Identity
- runFresh :: Fresh a -> FreshState -> (a, FreshState)
- evalFresh :: Fresh a -> FreshState -> a
- execFresh :: Fresh a -> FreshState -> FreshState
- newtype FreshT m a = FreshT {
- unFreshT :: StateT FreshState m a
- freshT :: (FreshState -> m (a, FreshState)) -> FreshT m a
- runFreshT :: FreshT m a -> FreshState -> m (a, FreshState)
- evalFreshT :: Monad m => FreshT m a -> FreshState -> m a
- execFreshT :: Monad m => FreshT m a -> FreshState -> m FreshState
- type FreshState = Integer
- nothingUsed :: FreshState
- module Control.Monad
- module Control.Monad.Fix
- module Control.Monad.Trans
MonadFresh class
class (Applicative m, Monad m) => MonadFresh m where #
Minimal complete definition
Methods
freshIdent :: String -> m Integer #
Get the integer of the next fresh identifier of this name.
freshIdents :: Integer -> m Integer #
Get a number of fresh identifiers. This reserves the required number of identifiers on all names.
scopeFreshness :: m a -> m a #
Scope the freshIdent
and freshIdents
requests such that these
variables are not marked as used once the scope is left.
Instances
MonadFresh m => MonadFresh (MaybeT m) # | |
Monad m => MonadFresh (FreshT m) # | |
Monad m => MonadFresh (FreshT m) # | |
MonadFresh m => MonadFresh (StateT s m) # | |
(Monoid w, MonadFresh m) => MonadFresh (WriterT w m) # | |
MonadFresh m => MonadFresh (ReaderT * r m) # | |
The Fresh monad
runFresh :: Fresh a -> FreshState -> (a, FreshState) #
Run a computation with a fresh name supply.
evalFresh :: Fresh a -> FreshState -> a #
Evaluate a computation with a fresh name supply.
execFresh :: Fresh a -> FreshState -> FreshState #
Execute a computation with a fresh name supply.
The fast FreshT monad transformer
A computation that can generate fresh variables from name hints.
Constructors
FreshT | |
Fields
|
Instances
MonadTrans FreshT # | |
MonadBind k v m => MonadBind k v (FreshT m) # | |
MonadError e m => MonadError e (FreshT m) # | |
MonadReader r m => MonadReader r (FreshT m) # | |
MonadState s m => MonadState s (FreshT m) # | |
Monad m => Monad (FreshT m) # | |
Functor m => Functor (FreshT m) # | |
Monad m => Applicative (FreshT m) # | |
MonadPlus m => Alternative (FreshT m) # | |
MonadPlus m => MonadPlus (FreshT m) # | |
Monad m => MonadFresh (FreshT m) # | |
MonadDisj m => MonadDisj (FreshT m) # | |
freshT :: (FreshState -> m (a, FreshState)) -> FreshT m a #
Construct a FreshT
action from a FreshState
modification.
runFreshT :: FreshT m a -> FreshState -> m (a, FreshState) #
Run a computation with a fresh name supply.
evalFreshT :: Monad m => FreshT m a -> FreshState -> m a #
Evaluate a computation with a fresh name supply.
execFreshT :: Monad m => FreshT m a -> FreshState -> m FreshState #
Execute a computation with a fresh name supply.
Fresh name generation
type FreshState = Integer #
The state of the name supply: the first unused sequence number of every name.
The empty fresh state.
module Control.Monad
module Control.Monad.Fix
module Control.Monad.Trans