I just found out about the GHC StablePointer function, which is really cool, but I cannot understand why it will not show things as equals. Here is my test case:
-- Example 1 import System.Mem.StableName data Wrapper = Wrapper { getWrapper :: Int -> Bool } myFunc :: Int -> Bool myFunc = (> 4) main :: IO () main = do let m = Wrapper myFunc a <- makeStableName $ getWrapper m b <- makeStableName $ getWrapper m print (a `eqStableName` b) putStrLn "Done"
Pretty simple, but when I do runhaskell with GHC 7.8.4, I get a false result. What about a simpler case? Let's try this:
-- Example 2 import System.Mem.StableName main :: IO () main = do let m = (+2) :: Int -> Int n = m a <- makeStableName m b <- makeStableName n print (a `eqStableName` b) putStrLn "Done"
I am still getting the result False. The only way to get eqStableName to return True is when I call makeStableName in the same exact bound variable. Like this:
-- in this example, r can be anything a <- makeStableName r b <- makeStableName r print (a `eqStableName` b)
But this is no longer useful. I already know that each expression is equal to itself, so this does not give me any new information. My question is twofold:
- What use
StablePointer are StablePointer designed to satisfy? - How can we talk about
StablePointer equality. I know that he gives false negatives, but under what circumstances can I expect that they will always take place?
Thanks for any ideas. They are very much appreciated.
- EDIT -
I found that if I build it using ghc instead of runhaskell , then example 2 really shows that they are equal. Example 1 is still not running. The question is still standing.
haskell ghc
Andrew Thaddeus Martin
source share