GHC Core question
Tim Chevalier
catamorphism at gmail.com
Sun Jan 6 19:14:43 EST 2008
On 1/5/08, Neil Mitchell <ndmitchell at gmail.com> wrote:
> 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?
>
How are you printing out the Core? It looks like the unique ids are
missing (you can see them if you pass the -ppr-debug flag, which can
be set using the API) -- if the unique ids were being printed, you
would see that the bindings for $dMonad (likely) have different
uniques.
Cheers,
Tim
--
Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
"...Losing your mind, like losing your car keys, is a real hassle." --
Andrew Solomon
More information about the Glasgow-haskell-users
mailing list