[Haskell-cafe] Does GHC compare pointers when eval'ing (==)

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Thu Aug 21 14:34:26 UTC 2014


On Wed, Aug 20, 2014 at 06:19:26PM -0700, John Meacham wrote:
> It is possible to do safely without breaking things when done in the IO Monad,
> 
> import System.Mem.StableName
> sameThing :: a -> a -> IO a
> sameThing x y = liftM2 (==) (makeStableName x) (makeStableName y)

I don't think this has the behaviour that Johan (the OP) wants.


import System.Mem.StableName
import Control.Monad

sameThing :: a -> a -> IO Bool
sameThing x y = liftM2 (==) (makeStableName x) (makeStableName y)

main = do
  let x = 1
      y = x
  print =<< sameThing x y
  print =<< sameThing x x

GHCi> main
False
True


I suspect Johan wants "True; True".

Tom


More information about the Haskell-Cafe mailing list