1 module NameSupply(NameSupply, initialNameSupply, splitNameSupply, getName, listNameSupply, Name(..)
2 #if defined(__YALE_HASKELL__)
7 #if defined(__YALE_HASKELL__)
12 # if defined(__GLASGOW_HASKELL__)
22 data NameSupply = NameSupply Name NameSupply NameSupply
24 splitNameSupply :: NameSupply -> (NameSupply,NameSupply)
25 getName :: NameSupply -> Name
26 listNameSupply :: NameSupply -> [NameSupply]
28 #if defined(__YALE_HASKELL__)
29 initialNameSupply :: IO NameSupply
31 initialNameSupply :: NameSupply
34 #if defined(__GLASGOW_HASKELL__)
35 initialNameSupply = unsafePerformPrimIO mk_supply# -- GHC-specific
38 = unsafeInterleavePrimIO (_ccall_ genSymZh)
40 unsafeInterleavePrimIO mk_supply# `thenPrimIO` \ s1 ->
41 unsafeInterleavePrimIO mk_supply# `thenPrimIO` \ s2 ->
42 returnPrimIO (NameSupply u s1 s2)
45 #if defined(__YALE_HASKELL__)
46 initialNameSupply :: IO NameSupply
50 unsafeInterleaveIO (genSymbol "NameSupply") >>= \ sym ->
51 unsafeInterleaveIO mk_supply >>= \ supply1 ->
52 unsafeInterleaveIO mk_supply >>= \ supply2 ->
53 return (NameSupply sym supply1 supply2)
59 initialNameSupply = gen ()
60 where gen n = NameSupply (__gensym n) (gen n) (gen n)
63 splitNameSupply (NameSupply _ s1 s2) = (s1, s2)
65 getName (NameSupply k _ _) = k
67 listNameSupply (NameSupply _ s1 s2) = s1 : listNameSupply s2