UniqSupply

ghc-8.6.5: The GHC API

Safe Haskell | None
Language | Haskell2010

UniqSupply

Contents

- Main data type
  - Operations on supplies
- Unique supply monad and its abstraction
  - Operations on the monad
- Set supply strategy

Synopsis

- data UniqSupply
- uniqFromSupply :: UniqSupply -> Unique
- uniqsFromSupply :: UniqSupply -> [Unique]
- takeUniqFromSupply :: UniqSupply -> (Unique, UniqSupply)
- mkSplitUniqSupply :: Char -> IO UniqSupply
- splitUniqSupply :: UniqSupply -> (UniqSupply, UniqSupply)
- listSplitUniqSupply :: UniqSupply -> [UniqSupply]
- splitUniqSupply3 :: UniqSupply -> (UniqSupply, UniqSupply, UniqSupply)
- splitUniqSupply4 :: UniqSupply -> (UniqSupply, UniqSupply, UniqSupply, UniqSupply)
- data UniqSM result
- class Monad m => MonadUnique m where
  - getUniqueSupplyM :: m UniqSupply
  - getUniqueM :: m Unique
  - getUniquesM :: m [Unique]
- liftUs :: MonadUnique m => UniqSM a -> m a
- initUs :: UniqSupply -> UniqSM a -> (a, UniqSupply)
- initUs_ :: UniqSupply -> UniqSM a -> a
- lazyThenUs :: UniqSM a -> (a -> UniqSM b) -> UniqSM b
- lazyMapUs :: (a -> UniqSM b) -> [a] -> UniqSM [b]
- getUniqueSupplyM3 :: MonadUnique m => m (UniqSupply, UniqSupply, UniqSupply)
- initUniqSupply :: Int -> Int -> IO ()

# Main data type

data UniqSupply #

Unique Supply

A value of type `UniqSupply` is unique, and it can supply one distinct `Unique`. Also, from the supply, one can also manufacture an arbitrary number of further `UniqueSupply` values, which will be distinct from the first and from all others.

## Operations on supplies

uniqFromSupply :: UniqSupply -> Unique #

Obtain the `Unique` from this particular `UniqSupply`

uniqsFromSupply :: UniqSupply -> [Unique] #

Obtain an infinite list of `Unique` that can be generated by constant splitting of the supply

takeUniqFromSupply :: UniqSupply -> (Unique, UniqSupply) #

Obtain the `Unique` from this particular `UniqSupply`, and a new supply

mkSplitUniqSupply :: Char -> IO UniqSupply #

Create a unique supply out of thin air. The character given must be distinct from those of all calls to this function in the compiler for the values generated to be truly unique.

splitUniqSupply :: UniqSupply -> (UniqSupply, UniqSupply) #

Build two `UniqSupply` from a single one, each of which can supply its own `Unique`.

listSplitUniqSupply :: UniqSupply -> [UniqSupply] #

Create an infinite list of `UniqSupply` from a single one

splitUniqSupply3 :: UniqSupply -> (UniqSupply, UniqSupply, UniqSupply) #

Build three `UniqSupply` from a single one, each of which can supply its own unique

splitUniqSupply4 :: UniqSupply -> (UniqSupply, UniqSupply, UniqSupply, UniqSupply) #

Build four `UniqSupply` from a single one, each of which can supply its own unique

# Unique supply monad and its abstraction

data UniqSM result #

A monad which just gives the ability to obtain `Unique`s

Instances

Monad UniqSM # |
Instance details Defined in UniqSupply Methods (>>=) :: UniqSM a -> (a -> UniqSM b) -> UniqSM b Source # (>>) :: UniqSM a -> UniqSM b -> UniqSM b Source # return :: a -> UniqSM a Source # fail :: String -> UniqSM a Source #
Functor UniqSM # |
Instance details Defined in UniqSupply Methods fmap :: (a -> b) -> UniqSM a -> UniqSM b Source # (<$) :: a -> UniqSM b -> UniqSM a Source #
MonadFix UniqSM # |
Instance details Defined in UniqSupply Methods mfix :: (a -> UniqSM a) -> UniqSM a Source #
MonadFail UniqSM # |
Instance details Defined in UniqSupply Methods fail :: String -> UniqSM a Source #
Applicative UniqSM # |
Instance details Defined in UniqSupply Methods pure :: a -> UniqSM a Source # (<*>) :: UniqSM (a -> b) -> UniqSM a -> UniqSM b Source # liftA2 :: (a -> b -> c) -> UniqSM a -> UniqSM b -> UniqSM c Source # (*>) :: UniqSM a -> UniqSM b -> UniqSM b Source # (<*) :: UniqSM a -> UniqSM b -> UniqSM a Source #
MonadUnique UniqSM # |
Instance details Defined in UniqSupply Methods getUniqueSupplyM :: UniqSM UniqSupply # getUniqueM :: UniqSM Unique # getUniquesM :: UniqSM [Unique] #

class Monad m => MonadUnique m where #

A monad for generating unique identifiers

Minimal complete definition

getUniqueSupplyM

Methods

getUniqueSupplyM :: m UniqSupply #

Get a new UniqueSupply

getUniqueM :: m Unique #

Get a new unique identifier

getUniquesM :: m [Unique] #

Get an infinite list of new unique identifiers

Instances

MonadUnique UniqSM # |
Instance details Defined in UniqSupply Methods getUniqueSupplyM :: UniqSM UniqSupply # getUniqueM :: UniqSM Unique # getUniquesM :: UniqSM [Unique] #
MonadUnique CoreM # |
Instance details Defined in CoreMonad Methods getUniqueSupplyM :: CoreM UniqSupply # getUniqueM :: CoreM Unique # getUniquesM :: CoreM [Unique] #
MonadUnique LlvmM # |
Instance details Defined in LlvmCodeGen.Base Methods getUniqueSupplyM :: LlvmM UniqSupply # getUniqueM :: LlvmM Unique # getUniquesM :: LlvmM [Unique] #
MonadUnique FCode # |
Instance details Defined in StgCmmMonad Methods getUniqueSupplyM :: FCode UniqSupply # getUniqueM :: FCode Unique # getUniquesM :: FCode [Unique] #
MonadUnique CmmParse # |
Instance details Defined in StgCmmExtCode Methods getUniqueSupplyM :: CmmParse UniqSupply # getUniqueM :: CmmParse Unique # getUniquesM :: CmmParse [Unique] #
MonadUnique SimplM # |
Instance details Defined in SimplMonad Methods getUniqueSupplyM :: SimplM UniqSupply # getUniqueM :: SimplM Unique # getUniquesM :: SimplM [Unique] #
MonadUnique TcS # |
Instance details Defined in TcSMonad Methods getUniqueSupplyM :: TcS UniqSupply # getUniqueM :: TcS Unique # getUniquesM :: TcS [Unique] #
MonadUnique NatM # |
Instance details Defined in NCGMonad Methods getUniqueSupplyM :: NatM UniqSupply # getUniqueM :: NatM Unique # getUniquesM :: NatM [Unique] #
MonadUnique (IOEnv (Env gbl lcl)) # |
Instance details Defined in TcRnMonad Methods getUniqueSupplyM :: IOEnv (Env gbl lcl) UniqSupply # getUniqueM :: IOEnv (Env gbl lcl) Unique # getUniquesM :: IOEnv (Env gbl lcl) [Unique] #

liftUs :: MonadUnique m => UniqSM a -> m a #

## Operations on the monad

initUs :: UniqSupply -> UniqSM a -> (a, UniqSupply) #

Run the `UniqSM` action, returning the final `UniqSupply`

initUs_ :: UniqSupply -> UniqSM a -> a #

Run the `UniqSM` action, discarding the final `UniqSupply`

lazyThenUs :: UniqSM a -> (a -> UniqSM b) -> UniqSM b #

lazyMapUs :: (a -> UniqSM b) -> [a] -> UniqSM [b] #

getUniqueSupplyM3 :: MonadUnique m => m (UniqSupply, UniqSupply, UniqSupply) #

# Set supply strategy

initUniqSupply :: Int -> Int -> IO () #