[Haskell-cafe] Where is SNMap for stable names?
Edward Kmett
ekmett at gmail.com
Thu Sep 22 21:36:06 CEST 2011
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 <mokus at deepbondi.net> wrote:
> 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
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110922/4f755c37/attachment.htm>
More information about the Haskell-Cafe
mailing list