
Then "don't do that." =) I should have mentioned, parametric keys are a no
no and can do bad things. ;)
-Edward
On Thu, Sep 22, 2011 at 2:33 PM, James Cook
I may be wrong, but I think the original SNMap was a map from 'StableName's to the specific values they were derived from, which also (IIRC) had some weak referencing aspect as well. Using them as keys for arbitrary elements of the phantom type is actually not type-safe, because equality of 'StableName's does not imply equality of types. Here's a simple demonstration (also at [1] with slightly more commentary) which defines a working equivalent of 'return unsafeCoerce' without directly using any "unsafe" function:
import Prelude hiding (lookup)
import Data.Functor.Identity import System.Mem.StableName import System.Mem.StableName.Map
unsafeCoerceIO :: IO (a -> b) unsafeCoerceIO = do sn1 <- makeStableName undefined sn2 <- makeStableName undefined
return $ \x -> let m = singleton sn1 (Identity x) Just (Identity y) = lookup sn2 m in y
main :: IO () main = do unsafeCoerce <- unsafeCoerceIO unsafeCoerce () "what did you do to my argument stack?!"
-- James
[1] https://github.com/mokus0/junkbox/blob/master/Haskell/TypeExperiments/Unsafe...