unbound-generics-0.2: Support for programming with names and binders using GHC Generics

Copyright(c) 2011, Stephanie Weirich
LicenseBSD3 (See LFresh.hs)
MaintainerAleksey Kliger
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010
Extensions
  • Cpp
  • UndecidableInstances
  • TypeSynonymInstances
  • FlexibleInstances
  • MultiParamTypeClasses
  • GeneralizedNewtypeDeriving

Unbound.Generics.LocallyNameless.LFresh

Contents

Description

Local freshness monad.

Synopsis

The LFresh class

class Monad m => LFresh m where Source

This is the class of monads that support freshness in an (implicit) local scope. Generated names are fresh for the current local scope, not necessarily globally fresh.

Methods

lfresh :: Typeable a => Name a -> m (Name a) Source

Pick a new name that is fresh for the current (implicit) scope.

avoid :: [AnyName] -> m a -> m a Source

Avoid the given names when freshening in the subcomputation, that is, add the given names to the in-scope set.

getAvoids :: m (Set AnyName) Source

Get the set of names currently being avoided.

Instances

LFresh m => LFresh (IdentityT m) 
LFresh m => LFresh (ListT m) 
LFresh m => LFresh (MaybeT m) 
Monad m => LFresh (LFreshMT m) 
LFresh m => LFresh (ContT r m) 
LFresh m => LFresh (ReaderT r m) 
LFresh m => LFresh (StateT s m) 
LFresh m => LFresh (StateT s m) 
LFresh m => LFresh (ExceptT e m) 
(Error e, LFresh m) => LFresh (ErrorT e m) 
(Monoid w, LFresh m) => LFresh (WriterT w m) 
(Monoid w, LFresh m) => LFresh (WriterT w m) 

type LFreshM = LFreshMT Identity Source

A convenient monad which is an instance of LFresh. It keeps track of a set of names to avoid, and when asked for a fresh one will choose the first unused numerical name.

runLFreshM :: LFreshM a -> a Source

Run a LFreshM computation in an empty context.

contLFreshM :: LFreshM a -> Set AnyName -> a Source

Run a LFreshM computation given a set of names to avoid.

newtype LFreshMT m a Source

The LFresh monad transformer. Keeps track of a set of names to avoid, and when asked for a fresh one will choose the first numeric prefix of the given name which is currently unused.

Constructors

LFreshMT 

Fields

unLFreshMT :: ReaderT (Set AnyName) m a
 

runLFreshMT :: LFreshMT m a -> m a Source

Run an LFreshMT computation in an empty context.

contLFreshMT :: LFreshMT m a -> Set AnyName -> m a Source

Run an LFreshMT computation given a set of names to avoid.