[Haskell-cafe] Where is SNMap for stable names?

James Cook mokus at deepbondi.net
Thu Sep 22 20:33:54 CEST 2011


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 <leather at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110922/4e9f89f8/attachment.htm>


More information about the Haskell-Cafe mailing list