unique identifiers as a separate library

Simon Marlow marlowsd at gmail.com
Thu Dec 18 10:11:33 EST 2008

Sebastian Fischer wrote:

> for a project I am using the libraries Unique, UniqSupply, and UniqFM 
> from the package ghc. It seems odd to have a dependency on a whole 
> compiler only in order to use its (highly efficient and, hence, 
> preferred) implementation of unique identifiers.
> Would it be possible to put everything concerned with unique identifiers 
> in GHC into a separate package on Hackage?
> This may also allow me to get a fix for 
> <http://hackage.haskell.org/trac/ghc/ticket/2880> without reinstalling GHC.

Sure, that would be a useful chunk to separate out from GHC.  However, 
looking at the code I see that our unique supply monad is really not a lazy 
  monad at all:

thenUs :: UniqSM a -> (a -> UniqSM b) -> UniqSM b
thenUs expr cont us
   = case (expr us) of { (result, us') -> cont result us' }

which is strict, and even the lazy version:

lazyThenUs :: UniqSM a -> (a -> UniqSM b) -> UniqSM b
lazyThenUs (USM expr) cont
   = USM (\us -> let (result, us') = expr us in unUSM (cont result) us')

doesn't really split the supply, because it will force the left side as 
soon as the unique on the right side is demanded.

Given that our monad is strict, there's no need for it to use 
mkSplitUniqueSupply, it could just call genSym to create new uniques.  I 
notice there are other parts of the compiler that do make use of the lazy 
splittable unique supply in their own monads, but I'm not sure if they 
really need it.


More information about the Glasgow-haskell-users mailing list