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.

Invoking again, with "-fobject-code". Note the absense of "interpreted" message:

  $ ghc-7.4.1 --interactive -fobject-code 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, UCSN.o )
  Ok, modules loaded: UCSN.
  ghci> :main
  type enter
  True
  ghci> :q
  Leaving GHCi.

Now we have "UCSN.hi" and "UCSN.o".

  $ ls
  UCSN.hi  UCSN.hs  UCSN.o

Invoking ghci again, without "-fobject-code".
No "interpreted" message. Showing 'True' with main.

  $ 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.
  Ok, modules loaded: UCSN.
  ghci> :main
  type enter
  True
  ghci> :q
  Leaving GHCi.


Hope these help.


[1]: 
http://www.haskell.org/ghc/docs/latest/html/users_guide/options-phases.html#options-codegen


Regards,
--
Atsuro

On Thu, Jun 28, 2012 at 6:41 AM, Facundo Domínguez
<facundoming...@gmail.com> 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)
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users@haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to