Where is SNMap for stable names?

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

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
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

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... 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
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

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...

Hi Edward, On Thu, Sep 22, 2011 at 16:50, Edward Kmett wrote:
I have a "stable-maps" package that provides lookup and inserting into a map via stable names.
The paper mentions the need for a mutable finite map, and all the operations are IO. Do you know why this is and what's different with your pure implementation? Regards, Sean

You still need IO to get the stable name out to use. :)
Sent from my iPad
On Sep 23, 2011, at 5:33 AM, Sean Leather
Hi Edward,
On Thu, Sep 22, 2011 at 16:50, Edward Kmett wrote: I have a "stable-maps" package that provides lookup and inserting into a map via stable names.
The paper mentions the need for a mutable finite map, and all the operations are IO. Do you know why this is and what's different with your pure implementation?
Regards, Sean

On Sat, Sep 24, 2011 at 01:41, Edward Kmett wrote:
You still need IO to get the stable name out to use. :)
I don't understand this statement. Consider the lookup operation in the paper and in your System.Mem.StableName.Map:
lookupSNMap :: SNMap k v -> StableName k -> IO (Maybe v)
lookup :: StableName a -> Map f -> Maybe (f a)
Unless you are intending f to be instantiated to IO -- which is not how I read it -- then, lookupSNMap is requiring some aspect of IO, probably mutability, and lookup is not. I am wondering if there is some fundamental difference between the two. Is the paper using immutability only for performance reasons? In that case, it's not a fundamental difference. Regards, Sean Sent from my iPad
On Sep 23, 2011, at 5:33 AM, Sean Leather
wrote: Hi Edward,
On Thu, Sep 22, 2011 at 16:50, Edward Kmett wrote:
I have a "stable-maps" package that provides lookup and inserting into a map via stable names.
The paper mentions the need for a mutable finite map, and all the operations are IO. Do you know why this is and what's different with your pure implementation?
Regards, Sean

How do you do that, since Stable Names have not an Ord instance?. Using the
Eq instance the lookup should be O(n).
The paper suggest that SNMap is a hash table, presumably with
hashStableNames underneath:
This should work more or less . using Data.HashTable
Import Data.HashTable
import Data.Dynamic
table :: HashTable StableName Dynamic
table= new (==) hashStableName
2011/9/22 Edward Kmett
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
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

I use hashStableName to split the names up then walk down the list use equality comparisons on an expected O(1) items. I'll probably rewrite it using unordered containers, since Tibbe does the same sans the stable names.
Sent from my iPad
On Sep 23, 2011, at 5:54 AM, "Alberto G. Corona "
How do you do that, since Stable Names have not an Ord instance?. Using the Eq instance the lookup should be O(n).
The paper suggest that SNMap is a hash table, presumably with hashStableNames underneath:
This should work more or less . using Data.HashTable
Import Data.HashTable import Data.Dynamic
table :: HashTable StableName Dynamic
table= new (==) hashStableName
2011/9/22 Edward Kmett
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
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
participants (4)
-
Alberto G. Corona
-
Edward Kmett
-
James Cook
-
Sean Leather