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/UnsafeStableMap.hs
 

On Sep 22, 2011, at 10:50 AM, Edward Kmett wrote:

> I have a "stable-maps" package that provides lookup and inserting into a map 
> via stable names.
> 
> -Edward
> 
> On Thu, Sep 22, 2011 at 5:47 AM, Sean Leather <leat...@cs.uu.nl> wrote:
> There is an abstract type called SNMap for stable names referred to in [1]. 
> This has apparently disappeared from GHC a long time ago. Is it still 
> available somewhere, or is there a suitable replacement for it?
> 
> Regards,
> Sean
> 
> [1] "Stretching the storage manager: weak pointers and stable names in 
> Haskell" - http://research.microsoft.com/apps/pubs/default.aspx?id=67497
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to