GHC Core question

Simon Peyton-Jones simonpj at microsoft.com
Mon Jan 7 03:50:40 EST 2008


If you use -dppr-debug GHC will show you the unique number of each identifier, and that'll show you that the two $dMonads are distinct even though they have the same print-name.  CoreTidy makes the print-name unique too.

Perhaps the Core printer should be a bit keener to print unique numbers, but it adds a lot of clutter.

Simon

| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-bounces at haskell.org] On Behalf Of
| Neil Mitchell
| Sent: 05 January 2008 20:01
| To: GHC Users
| Subject: GHC Core question
|
| Hi
|
| I've compiled the Debug.Trace module to Core, but can't understand the
| resulting output. The original code is:
|
| trace string expr = unsafePerformIO $ do
|     putTraceMsg string
|     return expr
|
| The core is:
|
| Debug.Trace.trace =
|    \ (@ a) ->
|      __letrec {
|        trace :: GHC.Base.String -> a -> a
|        []
|        trace =
|          \ (string :: GHC.Base.String) (expr :: a) ->
|            GHC.Base.$
|              @ (GHC.IOBase.IO a)
|              @ a
|              (GHC.IOBase.unsafePerformIO @ a)
|              (>> @ () @ a (Debug.Trace.putTraceMsg string) (return @ a expr));
|        $dMonad :: GHC.Base.Monad GHC.IOBase.IO
|        []
|        $dMonad = $dMonad;
|        return :: forall a. a -> GHC.IOBase.IO a
|        []
|        return = GHC.Base.return @ GHC.IOBase.IO $dMonad;
|        $dMonad :: GHC.Base.Monad GHC.IOBase.IO
|        []
|        $dMonad = GHC.IOBase.$f16;
|        >> :: forall a b.
|              GHC.IOBase.IO a -> GHC.IOBase.IO b -> GHC.IOBase.IO b
|        []
|        >> = GHC.Base.>> @ GHC.IOBase.IO $dMonad;
|      } in  trace;
|
| And my Haskell reformatting of that is:
|
| Debug.Trace.trace = let
|        trace string expr = unsafePerformIO $ putTraceMsg string >> return expr
|        $dMonad = $dMonad;
|        return = GHC.Base.return $dMonad;
|        $dMonad = GHC.IOBase.$f16;
|        >> = GHC.Base.>> $dMonad;
|     in  trace
|
| However, that let expression has two bindings for $dMonad, one of
| which looks like a black-hole. Are the semantics of __letrec different
| from let in some way?
|
| Thanks
|
| Neil
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


More information about the Glasgow-haskell-users mailing list