| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Futhark.MonadFreshNames
Description
This module provides a monadic facility similar (and built on top
of) Futhark.FreshNames. The removes the need for a (small) amount of
boilerplate, at the cost of using some GHC extensions. The idea is
that if your compiler pass runs in a monad that is an instance of
MonadFreshNames, you can automatically use the name generation
functions exported by this module.
Synopsis
- class Monad m => MonadFreshNames (m :: Type -> Type) where
- getNameSource :: m VNameSource
- putNameSource :: VNameSource -> m ()
- modifyNameSource :: MonadFreshNames m => (VNameSource -> (a, VNameSource)) -> m a
- newName :: MonadFreshNames m => VName -> m VName
- newVName :: MonadFreshNames m => Name -> m VName
- newIdent :: MonadFreshNames m => Name -> Type -> m Ident
- newIdent' :: MonadFreshNames m => (Name -> Name) -> Ident -> m Ident
- newParam :: MonadFreshNames m => Name -> dec -> m (Param dec)
- newtype VNameSource = VNameSource Int
- blankNameSource :: VNameSource
- newNameSource :: Int -> VNameSource
Documentation
class Monad m => MonadFreshNames (m :: Type -> Type) where Source #
A monad that stores a name source. The following is a good
instance for a monad in which the only state is a NameSource vn:
instance MonadFreshNames vn MyMonad where getNameSource = get putNameSource = put
Instances
modifyNameSource :: MonadFreshNames m => (VNameSource -> (a, VNameSource)) -> m a Source #
Run a computation needing a fresh name source and returning a new
one, using getNameSource and putNameSource before and after the
computation.
newName :: MonadFreshNames m => VName -> m VName Source #
Produce a fresh name, using the given name as a template.
newVName :: MonadFreshNames m => Name -> m VName Source #
Produce a fresh VName, using the given base name as a template.
newIdent :: MonadFreshNames m => Name -> Type -> m Ident Source #
Produce a fresh Ident, using the given name as a template.
newParam :: MonadFreshNames m => Name -> dec -> m (Param dec) Source #
Produce a fresh Param, using the given name as a template.
newtype VNameSource Source #
A name source is conceptually an infinite sequence of names with no repeating entries. In practice, when asked for a name, the name source will return the name along with a new name source, which should then be used in place of the original.
The Ord instance is based on how many names have been extracted
from the name source.
Constructors
| VNameSource Int |
Instances
blankNameSource :: VNameSource Source #
A blank name source.
newNameSource :: Int -> VNameSource Source #
A new name source that starts counting from the given number.