I'm trying to better understand how a GHC produced TypedcheckedSource is composed. I have this little example:<div><br></div><div><div><font face="courier new, monospace">module Test</font></div><div><font face="courier new, monospace"> ( mysum</font></div>
<div><font face="courier new, monospace"> ) where</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">import Data.List (foldl')</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">mysum :: [Int] -> Int</font></div><div><font face="courier new, monospace">mysum xs = foldl' (+) 0 xs</font></div><div><br></div></div><div>Pretty-printing TypecheckedSource gives me something like this:</div>
<div><br></div><div><div><font face="courier new, monospace">{{Test.hs:7:10-21}</font></div><div><font face="courier new, monospace"> AbsBinds [] []</font></div><div><font face="courier new, monospace"> {Exports: [main:Test.mysum{v rgu} [lid] <= mysum{v agP} [lid]</font></div>
<div><font face="courier new, monospace"> <>]</font></div><div><font face="courier new, monospace"> Exported types: main:Test.mysum{v rgu} [lid]</font></div><div><font face="courier new, monospace"> :: [ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}]</font></div>
<div><font face="courier new, monospace"> -> ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}</font></div><div><font face="courier new, monospace"> [LclId]</font></div>
<div><font face="courier new, monospace"> Binds: {Test.hs:8:1-26}</font></div><div><font face="courier new, monospace"> mysum{v agP} [lid]</font></div><div><font face="courier new, monospace"> :: [ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}]</font></div>
<div><font face="courier new, monospace"> -> ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}</font></div><div><font face="courier new, monospace"> [LclId]</font></div><div>
<font face="courier new, monospace"> mysum{v agP} [lid]</font></div><div><font face="courier new, monospace"> ((xs{v agw} [lid] :: [ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}]))</font></div>
<div><font face="courier new, monospace"> = {Test.hs:8:12-26}</font></div><div><font face="courier new, monospace"> (base:Data.List.foldl'{v r4u}) @ ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}</font></div>
<div><font face="courier new, monospace"> @ ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}</font></div><div><font face="courier new, monospace"> (((base:GHC.Num.+{v rt})) @ ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}</font></div>
<div><font face="courier new, monospace"> $dNum{v agU} [lid])</font></div><div><font face="courier new, monospace"> 0 ((base:GHC.Num.fromInteger{v 02A})</font></div><div><font face="courier new, monospace"> @ ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}</font></div>
<div><font face="courier new, monospace"> $dNum{v ahc} [lid]</font></div><div><font face="courier new, monospace"> 0)</font></div><div><font face="courier new, monospace"> xs{v agw}</font></div>
<div><font face="courier new, monospace"> <></font></div><div><font face="courier new, monospace"> Evidence: EvBinds{}}} {Test.hs:7:1-21}</font></div><div><font face="courier new, monospace"> main:Test.mysum{v rgu} ::</font></div>
<div><font face="courier new, monospace"> {Test.hs:7:10-21}</font></div><div><font face="courier new, monospace"> [ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}]</font></div>
<div><font face="courier new, monospace"> -> ghc-prim:<a href="http://GHC.Types.Int">GHC.Types.Int</a>{(w) tc 3J}</font></div><div><font face="courier new, monospace"> nonrec {Test.hs:8:1-26}</font></div>
<div><font face="courier new, monospace"> main:Test.mysum{v rgu}</font></div><div><font face="courier new, monospace"> main:Test.mysum{v rgu} (xs{v agw})</font></div>
<div><font face="courier new, monospace"> = {Test.hs:8:12-26}</font></div><div><font face="courier new, monospace"> base:Data.List.foldl'{v r4u}</font></div>
<div><font face="courier new, monospace"> (base:GHC.Num.+{v rt})</font></div><div><font face="courier new, monospace"> 0 (base:GHC.Num.fromInteger{v 02A})</font></div>
<div><font face="courier new, monospace"> xs{v agw}</font></div><div><font face="courier new, monospace"> <></font></div></div><div><br></div><div>
This doesn't really help me understand the AST any better, as this is essentially the source printed back to me. What I would like to see is something like:</div><div><br></div><div><font face="courier new, monospace">HsApp (HsApp (HsApp (HsVar "foldl'") (HsVar "+")) (HsLit 0)) (HsVar "xs")</font></div>
<div><br></div><div>Is this possible today. If not, can we derive Show for all the GHC data types so it's possible to print their structure?</div><div><br></div><div>P.S. An example of why the pretty-printed output is not very helpful in understanding the AST: the above simple example generates a HsWrap constructor, which is nowhere to be seen in the pretty-printed output.</div>
<div><br></div><div>-- Johan</div><div><br></div>