The doc for HKey.withKey states:
"The implementation actually creates a key, but because the key cannot escape the given function f, there is no way to observe that if we run withKey f twice, that it will get a different key the second time."
But in the following we see it is possible.
Nick
{-#LANGUAGE ExistentialQuantification, RankNTypes #-}
module Main(main) where
import Data.HMap as HMap
data Wrapped = forall x. Wrapped (HKey x ())
create :: () -> Wrapped
create () = HMap.withKey Wrapped
x,y,z :: Wrapped
x = create ()
y = create ()
z = y
comp :: Wrapped -> Wrapped -> Bool
comp (Wrapped key1) (Wrapped key2) = HMap.unique key1 == HMap.unique key2
main :: IO ()
main = do
print ("x~y",comp x y)
print ("x~z",comp x z)
print ("y~z",comp y z)
{- Prints...
("x~y",False)
("x~z",False)
("y~z",True)
-}
The doc for HKey.withKey states:
"The implementation actually creates a key, but because the key cannot escape the given function f, there is no way to observe that if we run withKey f twice, that it will get a different key the second time."
But in the following we see it is possible.
Nick
{-#LANGUAGE ExistentialQuantification, RankNTypes #-} module Main(main) where import Data.HMap as HMap data Wrapped = forall x. Wrapped (HKey x ()) create :: () -> Wrapped create () = HMap.withKey Wrapped x,y,z :: Wrapped x = create () y = create () z = y comp :: Wrapped -> Wrapped -> Bool comp (Wrapped key1) (Wrapped key2) = HMap.unique key1 == HMap.unique key2 main :: IO () main = do print ("x~y",comp x y) print ("x~z",comp x z) print ("y~z",comp y z) {- Prints... ("x~y",False) ("x~z",False) ("y~z",True) -}