ghc-lib-parser-9.10.1.20250103: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Types.Unique.Supply

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)
- uniqFromTag :: Char -> IO Unique
- mkSplitUniqSupply :: Char -> IO UniqSupply
- splitUniqSupply :: UniqSupply -> (UniqSupply, UniqSupply)
- listSplitUniqSupply :: UniqSupply -> [UniqSupply]
- data UniqSM result
- class Monad m => MonadUnique (m :: Type -> Type) where
  - getUniqueSupplyM :: m UniqSupply
  - getUniqueM :: m Unique
  - getUniquesM :: m [Unique]
- initUs :: UniqSupply -> UniqSM a -> (a, UniqSupply)
- initUs_ :: UniqSupply -> UniqSM a -> a
- initUniqSupply :: Word64 -> 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

uniqFromTag :: Char -> IO Unique #

mkSplitUniqSupply :: Char -> IO UniqSupply #

Create a unique supply out of thin air. The "tag" (Char) supplied is purely cosmetic, making it easier to figure out where a Unique was born. See Note [Uniques and tags].

The payload part of the Uniques allocated from this UniqSupply are guaranteed distinct wrt all other supplies, regardless of their "tag". This is achieved by allocating the payload part from a single source of Uniques, namely `genSym`, shared across all UniqSupply's.

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

# Unique supply monad and its abstraction

data UniqSM result #

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

#### Instances

Instances details

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

class Monad m => MonadUnique (m :: Type -> Type) 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

Instances details

MonadUnique CoreM # |
Instance details Defined in GHC.Core.Opt.Monad Methods getUniqueSupplyM :: CoreM UniqSupply # getUniqueM :: CoreM Unique # getUniquesM :: CoreM [Unique] #
MonadUnique SimplM # |
Instance details Defined in GHC.Core.Opt.Simplify.Monad Methods getUniqueSupplyM :: SimplM UniqSupply # getUniqueM :: SimplM Unique # getUniquesM :: SimplM [Unique] #
MonadUnique UniqSM # |
Instance details Defined in GHC.Types.Unique.Supply Methods getUniqueSupplyM :: UniqSM UniqSupply # getUniqueM :: UniqSM Unique # getUniquesM :: UniqSM [Unique] #

## 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`

# Set supply strategy

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