X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FbasicTypes%2FUniqSupply.lhs;h=7bd84b3e9de37a51c5a0f084c64d3f531c592ac6;hb=75b2110801d1dcc1dba4b3d437c4a5f379e704e9;hp=2599d8d5f0f3e3bf1fdc0984583ed8f21f715b79;hpb=992bdde6de529002406a63abf94cb3e8a644bf3b;p=ghc-hetmet.git diff --git a/compiler/basicTypes/UniqSupply.lhs b/compiler/basicTypes/UniqSupply.lhs index 2599d8d..7bd84b3 100644 --- a/compiler/basicTypes/UniqSupply.lhs +++ b/compiler/basicTypes/UniqSupply.lhs @@ -20,11 +20,14 @@ module UniqSupply ( UniqSM, -- type: unique supply monad initUs, initUs_, lazyThenUs, lazyMapUs, - module MonadUtils, mapAndUnzipM, + mapAndUnzipM, MonadUnique(..), mkSplitUniqSupply, - splitUniqSupply, listSplitUniqSupply + splitUniqSupply, listSplitUniqSupply, + + -- Deprecated: + getUniqueUs, getUs, returnUs, thenUs, mapUs ) where #include "HsVersions.h" @@ -32,6 +35,9 @@ module UniqSupply ( import Unique import FastTypes +import MonadUtils +import Control.Monad +import Control.Monad.Fix #if __GLASGOW_HASKELL__ >= 607 import GHC.IOBase (unsafeDupableInterleaveIO) #else @@ -112,6 +118,16 @@ instance Monad UniqSM where (>>=) = thenUs (>>) = thenUs_ +instance Functor UniqSM where + fmap f (USM x) = USM (\us -> case x us of + (r, us') -> (f r, us')) + +instance Applicative UniqSM where + pure = returnUs + (USM f) <*> (USM x) = USM $ \us -> case f us of + (ff, us') -> case x us' of + (xx, us'') -> (ff xx, us'') + -- the initUs function also returns the final UniqSupply; initUs_ drops it initUs :: UniqSupply -> UniqSM a -> (a,UniqSupply) initUs init_us m = case unUSM m init_us of { (r,us) -> (r,us) } @@ -176,6 +192,13 @@ getUniqueUs = USM (\us -> case splitUniqSupply us of getUniquesUs :: UniqSM [Unique] getUniquesUs = USM (\us -> case splitUniqSupply us of (us1,us2) -> (uniqsFromSupply us1, us2)) + +mapUs :: (a -> UniqSM b) -> [a] -> UniqSM [b] +mapUs f [] = returnUs [] +mapUs f (x:xs) + = f x `thenUs` \ r -> + mapUs f xs `thenUs` \ rs -> + returnUs (r:rs) \end{code} \begin{code} @@ -189,5 +212,4 @@ lazyMapUs f (x:xs) = f x `lazyThenUs` \ r -> lazyMapUs f xs `lazyThenUs` \ rs -> returnUs (r:rs) - \end{code}