tamarin-prover-utils-1.2.2: Utility library for the tamarin prover.

Copyright | (c) 2010-2012 Simon Meier
License | GPL v3 (see LICENSE)
Maintainer | Simon Meier <iridcode@gmail.com>
Portability | GHC only
Safe Haskell | None
Language | Haskell98

Control.Monad.Trans.PreciseFresh

Contents

- The Fresh monad
- The FreshT monad transformer
- Fresh name generation

Description

A monad transformer for passing a fresh name supply through a computation. The name supply is precise in the sense that every `String` has its own supply of indices for the next fresh name.

Modeled after the mtl-2.0 library.

Synopsis

- 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 = Map String Integer
- nothingUsed :: FreshState
- freshIdent :: Monad m => String -> FreshT m Integer
- freshIdents :: Monad m => Integer -> FreshT m Integer
- scopeFreshness :: Monad m => FreshT m a -> FreshT m a

# The Fresh monad

type Fresh = FreshT Identity #

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 FreshT monad transformer

newtype FreshT m a #

A computation that can generate fresh variables from name hints.

Constructors

FreshT |
Fields unFreshT :: StateT FreshState m a

Instances

MonadTrans FreshT # |
Methods lift :: Monad m => m a -> FreshT m a #
MonadBind k v m => MonadBind k v (FreshT m) # |
MonadError e m => MonadError e (FreshT m) # |
Methods throwError :: e -> FreshT m a # catchError :: FreshT m a -> (e -> FreshT m a) -> FreshT m a #
MonadReader r m => MonadReader r (FreshT m) # |
Methods ask :: FreshT m r # local :: (r -> r) -> FreshT m a -> FreshT m a # reader :: (r -> a) -> FreshT m a #
MonadState s m => MonadState s (FreshT m) # |
Methods get :: FreshT m s # put :: s -> FreshT m () # state :: (s -> (a, s)) -> FreshT m a #
Monad m => Monad (FreshT m) # |
Methods (>>=) :: FreshT m a -> (a -> FreshT m b) -> FreshT m b # (>>) :: FreshT m a -> FreshT m b -> FreshT m b # return :: a -> FreshT m a # fail :: String -> FreshT m a #
Functor m => Functor (FreshT m) # |
Methods fmap :: (a -> b) -> FreshT m a -> FreshT m b # (<$) :: a -> FreshT m b -> FreshT m a #
Monad m => Applicative (FreshT m) # |
Methods pure :: a -> FreshT m a # (<*>) :: FreshT m (a -> b) -> FreshT m a -> FreshT m b # (*>) :: FreshT m a -> FreshT m b -> FreshT m b # (<*) :: FreshT m a -> FreshT m b -> FreshT m a #
MonadPlus m => Alternative (FreshT m) # |
Methods empty :: FreshT m a # (<|>) :: FreshT m a -> FreshT m a -> FreshT m a # some :: FreshT m a -> FreshT m [a] # many :: FreshT m a -> FreshT m [a] #
MonadPlus m => MonadPlus (FreshT m) # |
Methods mzero :: FreshT m a # mplus :: FreshT m a -> FreshT m a -> FreshT m a #
Monad m => MonadFresh (FreshT m) # |
Methods freshIdent :: String -> FreshT m Integer # freshIdents :: Integer -> FreshT m Integer # scopeFreshness :: FreshT m a -> FreshT m a #

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 #

execFreshT :: Monad m => FreshT m a -> FreshState -> m FreshState #

Execute a computation with a fresh name supply.

# Fresh name generation

type FreshState = Map String Integer #

The state of the name supply: the first unused sequence number of every name.

nothingUsed :: FreshState #

The empty fresh state.

freshIdent :: Monad m => String -> FreshT m Integer #

O(log(n)). Get a fresh identifier for the given name.

freshIdents #

Arguments

:: Monad m |
=> Integer | number of desired identifiers
-> FreshT m Integer | The first fresh identifier.

O(n). Get `k` fresh identifiers.

scopeFreshness :: Monad m => FreshT m a -> FreshT m a #

Restrict the scope of the freshness requests.