Facundo Domínguez | 27 Jun 23:41 2012
Picon

Strange behavior when using stable names inside ghci?

Hi,
  The program below when loaded in ghci prints always False, and when
compiled with ghc it prints True. I'm using ghc-7.4.1 and I cannot
quite explain such behavior. Any hints?

Thanks in advance,
Facundo

{-# LANGUAGE GADTs #-}
import System.Mem.StableName
import Unsafe.Coerce
import GHC.Conc

data D where
   D :: a -> b -> D

main = do
  putStr "type enter"
  s <- getLine
  let i = fromEnum$ head$ s++"0"
      d = D i i
  case d of
    D a b -> do
        let a' = a
        sn0 <- pseq a'$ makeStableName a'
        sn1 <- pseq b$ makeStableName b
        print (sn0==unsafeCoerce sn1)
Atsuro Hoshino | 28 Jun 08:49 2012
Picon

Re: Strange behavior when using stable names inside ghci?

Hi Facundo,

>  The program below when loaded in ghci prints always False, and when
> compiled with ghc it prints True

From above, I guess the code is not compiled in ghci, which means
byte-code is used insted of object-code.

If what matter here is "to get same result in ghci and compiled code",
invoking ghci with object code compilation option[1] may help. E.g.
start ghci with:

  $ ghci  -fobject-code

Below is a sample session with your code. I saved it as "UCSN.hs".

  $ ls
  UCSN.hs
  $ ghc-7.4.1 --interactive UCSN.hs
  GHCi, version 7.4.1: http://www.haskell.org/ghc/  :? for help
  Loading package ghc-prim ... linking ... done.
  Loading package integer-gmp ... linking ... done.
  Loading package base ... linking ... done.
  [1 of 1] Compiling UCSN             ( UCSN.hs, interpreted )
  Ok, modules loaded: UCSN.
  ghci> :main
  type enter
  False
  ghci> :q
  Leaving GHCi.
(Continue reading)

Simon Peyton-Jones | 28 Jun 09:42 2012
Picon

RE: Strange behavior when using stable names inside ghci?

You are, in effect, doing pointer equality here, which is certain to be fragile, ESPECIALLY if you are not
optimising the code (as is the case in GHCi).  I'd be inclined to seek a more robust way to solve whatever
problem you started with

Simon

|  -----Original Message-----
|  From: glasgow-haskell-users-bounces <at> haskell.org [mailto:glasgow-haskell-users-
|  bounces <at> haskell.org] On Behalf Of Facundo Domínguez
|  Sent: 27 June 2012 22:41
|  To: glasgow-haskell-users <at> haskell.org
|  Subject: Strange behavior when using stable names inside ghci?
|  
|  Hi,
|    The program below when loaded in ghci prints always False, and when
|  compiled with ghc it prints True. I'm using ghc-7.4.1 and I cannot
|  quite explain such behavior. Any hints?
|  
|  Thanks in advance,
|  Facundo
|  
|  {-# LANGUAGE GADTs #-}
|  import System.Mem.StableName
|  import Unsafe.Coerce
|  import GHC.Conc
|  
|  data D where
|     D :: a -> b -> D
|  
|  main = do
(Continue reading)

Facundo Domínguez | 28 Jun 15:36 2012
Picon

Re: Strange behavior when using stable names inside ghci?

I'm using StableNames to recover sharing in abstract syntax trees of
an embedded DSL, and I'm kind of following the approach of accelerate
[1]. I was expecting the stable name comparison to be slightly more
reliable. I'm pondering the alternatives.

Many thanks for the replies.
Facundo

[1] http://hackage.haskell.org/package/accelerate

On Thu, Jun 28, 2012 at 7:00 AM,
<glasgow-haskell-users-request <at> haskell.org> wrote:
> Send Glasgow-haskell-users mailing list submissions to
>        glasgow-haskell-users <at> haskell.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
> or, via email, send a message with subject or body 'help' to
>        glasgow-haskell-users-request <at> haskell.org
>
> You can reach the person managing the list at
>        glasgow-haskell-users-owner <at> haskell.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Glasgow-haskell-users digest..."
>
>
> Today's Topics:
>
>   1. Re: Fwd: ghc-7.6 branch (Gershom Bazerman)
(Continue reading)

Simon Marlow | 29 Jun 17:32 2012
Picon

Re: Strange behavior when using stable names inside ghci?

On 27/06/12 22:41, Facundo Domínguez wrote:
> Hi,
>    The program below when loaded in ghci prints always False, and when
> compiled with ghc it prints True. I'm using ghc-7.4.1 and I cannot
> quite explain such behavior. Any hints?
>
> Thanks in advance,
> Facundo
>
> {-# LANGUAGE GADTs #-}
> import System.Mem.StableName
> import Unsafe.Coerce
> import GHC.Conc
>
> data D where
>     D :: a ->  b ->  D
>
> main = do
>    putStr "type enter"
>    s<- getLine
>    let i = fromEnum$ head$ s++"0"
>        d = D i i
>    case d of
>      D a b ->  do
>          let a' = a
>          sn0<- pseq a'$ makeStableName a'
>          sn1<- pseq b$ makeStableName b
>          print (sn0==unsafeCoerce sn1)

GHCi adds some extra annotations around certain subexpressions to 
(Continue reading)


Gmane