I'm trying to better understand how a GHC produced TypedcheckedSource is composed. I have this little example:
module Test
( mysum
) where
import Data.List (foldl')
mysum :: [Int] -> Int
mysum xs = foldl' (+) 0 xs
Pretty-printing TypecheckedSource gives me something like this:
{{Test.hs:7:10-21}
AbsBinds [] []
{Exports: [main:Test.mysum{v rgu} [lid] <= mysum{v agP} [lid]
<>]
Exported types: main:Test.mysum{v rgu} [lid]
[LclId]
Binds: {Test.hs:8:1-26}
mysum{v agP} [lid]
[LclId]
mysum{v agP} [lid]
= {Test.hs:8:12-26}
(base:Data.List.foldl'{v r4u}) @ ghc-prim:GHC.Types.Int{(w) tc 3J}
$dNum{v agU} [lid])
0 ((base:GHC.Num.fromInteger{v 02A})
$dNum{v ahc} [lid]
0)
xs{v agw}
<>
Evidence: EvBinds{}}} {Test.hs:7:1-21}
main:Test.mysum{v rgu} ::
{Test.hs:7:10-21}
nonrec {Test.hs:8:1-26}
main:Test.mysum{v rgu}
main:Test.mysum{v rgu} (xs{v agw})
= {Test.hs:8:12-26}
base:Data.List.foldl'{v r4u}
(base:GHC.Num.+{v rt})
0 (base:GHC.Num.fromInteger{v 02A})
xs{v agw}
<>
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:
HsApp (HsApp (HsApp (HsVar "foldl'") (HsVar "+")) (HsLit 0)) (HsVar "xs")
Is this possible today. If not, can we derive Show for all the GHC data types so it's possible to print their structure?
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.
-- Johan