Here's our sample Haskell module for playing with the GHC AST
-- an example from http://blog.ezyang.com/2011/05/anatomy-of-a-thunk-leak/
module A05 ( main ) where
import Control.Exception ( evaluate )
main = evaluate (f [1..4000000] (0 :: Int, 1 :: Int))
f [] c = c
f (x:xs) c = f xs (tick x c)
tick x (c0, c1) | even x = (c0, c1 + 1)
| otherwise = (c0 + 1, c1)
This is the usual way to show the GHC (7.8.1) AST
(printForUser dflags stdout unqual . shown TypeChecker) typechecked
({abstract:Bag((Origin,(GenLocated SrcSpan (HsBindLR Var Var))))}
[
((,)
(FromSource)
(L {A06.hs:(14,3)-(15,44)}
(AbsBinds
[{Var: a},{Var: t},{Var: t}]
[{Var: $dNum_a1bS},{Var: $dNum_a1bT},{Var: $dIntegral_a1bU}]
[
(ABE {Var: A06.tick} {Var: tick}
(WpCompose
(WpCompose
(WpCompose
(WpCompose
(WpTyLam {Var: a})
(WpCompose
(WpTyLam {Var: t})
(WpTyLam {Var: t})))
(WpCompose
(WpEvLam {Var: $dNum_a1bZ})
(WpCompose
(WpEvLam {Var: $dNum_a1c0})
(WpEvLam {Var: $dIntegral_a1c1}))))
(WpLet
({abstract:TcEvBinds})))
(WpCompose
(WpCompose
(WpCompose
(WpEvApp
(EvId {Var: $dIntegral_a1c8}))
(WpEvApp
(EvId {Var: $dNum_a1c7})))
(WpEvApp
(EvId {Var: $dNum_a1c6})))
(WpCompose
(WpCompose
(WpTyApp t)
(WpTyApp t))
(WpTyApp a))))
(SpecPrags
[]))]
({abstract:TcEvBinds})
({abstract:Bag((Origin,(GenLocated SrcSpan (HsBindLR Var Var))))}
[
((,)
(FromSource)
(L {A06.hs:(14,3)-(15,44)}
(FunBind
(L {A06.hs:14:3-6} {Var: tick})
(False)
(MG
[
(L {A06.hs:(14,3)-(15,44)}
(Match
[
(L {A06.hs:14:8}
(VarPat {Var: x})),
(L {A06.hs:14:10-17}
(TuplePat
[
(L {A06.hs:14:11-12}
(VarPat {Var: c0})),
(L {A06.hs:14:15-16}
(VarPat {Var: c1}))]
(Boxed) (t, t)))]
(Nothing)
(GRHSs
[
(L {A06.hs:14:19-44}
(GRHS
[
(L {A06.hs:14:21-26}
(BodyStmt
(L {A06.hs:14:21-26}
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {A06.hs:14:21-24}
(HsWrap
(WpCompose
(WpEvApp
(EvId {Var: $dIntegral_a1bC}))
(WpTyApp a))
(HsVar {Var: GHC.Real.even})))
(L {A06.hs:14:26}
(HsVar {Var: x}))))))
(HsLit
(HsString {FastString: "noSyntaxExpr"}))
(HsLit
(HsString {FastString: "noSyntaxExpr"})) GHC.Types.Bool))]
(L {A06.hs:14:33-44}
(ExplicitTuple
[
(Present
(L {A06.hs:14:34-35}
(HsVar {Var: c0}))),
(Present
(L {A06.hs:14:38-43}
(OpApp
(L {A06.hs:14:38-39}
(HsVar {Var: c1}))
(L {A06.hs:14:41}
(HsWrap
(WpCompose
(WpEvApp
(EvId {Var: $dNum_a1bG}))
(WpTyApp t))
(HsVar {Var: GHC.Num.+}))) {Fixity: infixl 6}
(L {A06.hs:14:43}
(HsOverLit
(OverLit
(HsIntegral
(1))
(False)
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {<no location info>}
(HsWrap
(WpCompose
(WpEvApp
(EvId {Var: $dNum_a1bI}))
(WpTyApp t))
(HsVar {Var: GHC.Num.fromInteger})))
(L {<no location info>}
(HsLit
(HsInteger
(1) GHC.Integer.Type.Integer)))))) t))))))]
(Boxed))))),
(L {A06.hs:15:19-44}
(GRHS
[
(L {A06.hs:15:21-29}
(BodyStmt
(L {A06.hs:15:21-29}
(HsVar {Var: GHC.Base.otherwise}))
(HsLit
(HsString {FastString: "noSyntaxExpr"}))
(HsLit
(HsString {FastString: "noSyntaxExpr"})) GHC.Types.Bool))]
(L {A06.hs:15:33-44}
(ExplicitTuple
[
(Present
(L {A06.hs:15:34-39}
(OpApp
(L {A06.hs:15:34-35}
(HsVar {Var: c0}))
(L {A06.hs:15:37}
(HsWrap
(WpCompose
(WpEvApp
(EvId {Var: $dNum_a1bK}))
(WpTyApp t))
(HsVar {Var: GHC.Num.+}))) {Fixity: infixl 6}
(L {A06.hs:15:39}
(HsOverLit
(OverLit
(HsIntegral
(1))
(False)
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {<no location info>}
(HsWrap
(WpCompose
(WpEvApp
(EvId {Var: $dNum_a1bM}))
(WpTyApp t))
(HsVar {Var: GHC.Num.fromInteger})))
(L {<no location info>}
(HsLit
(HsInteger
(1) GHC.Integer.Type.Integer)))))) t)))))),
(Present
(L {A06.hs:15:42-43}
(HsVar {Var: c1})))]
(Boxed)))))]
(EmptyLocalBinds))))]
[a,(t, t)] (t, t))
(WpHole) {!NameSet placeholder here!}
(Nothing))))])))),
((,)
(FromSource)
(L {A06.hs:(11,3)-(12,30)}
(AbsBinds
[{Var: a},{Var: t},{Var: t}]
[{Var: $dNum_a1cy},{Var: $dNum_a1cz},{Var: $dIntegral_a1cA}]
[
(ABE {Var: A06.f} {Var: f}
(WpCompose
(WpCompose
(WpCompose
(WpCompose
(WpTyLam {Var: a})
(WpCompose
(WpTyLam {Var: t})
(WpTyLam {Var: t})))
(WpCompose
(WpEvLam {Var: $dNum_a1cF})
(WpCompose
(WpEvLam {Var: $dNum_a1cG})
(WpEvLam {Var: $dIntegral_a1cH}))))
(WpLet
({abstract:TcEvBinds})))
(WpCompose
(WpCompose
(WpCompose
(WpEvApp
(EvId {Var: $dIntegral_a1cO}))
(WpEvApp
(EvId {Var: $dNum_a1cN})))
(WpEvApp
(EvId {Var: $dNum_a1cM})))
(WpCompose
(WpCompose
(WpTyApp t)
(WpTyApp t))
(WpTyApp a))))
(SpecPrags
[]))]
({abstract:TcEvBinds})
({abstract:Bag((Origin,(GenLocated SrcSpan (HsBindLR Var Var))))}
[
((,)
(FromSource)
(L {A06.hs:(11,3)-(12,30)}
(FunBind
(L {A06.hs:11:3} {Var: f})
(False)
(MG
[
(L {A06.hs:11:3-16}
(Match
[
(L {A06.hs:11:5-6}
(ConPatOut
(L {A06.hs:11:5-6}
({abstract:ConLike}))
[]
[]
({abstract:TcEvBinds})
(PrefixCon
[]) [a]
(WpHole))),
(L {A06.hs:11:12}
(VarPat {Var: c}))]
(Nothing)
(GRHSs
[
(L {A06.hs:11:16}
(GRHS
[]
(L {A06.hs:11:16}
(HsVar {Var: c}))))]
(EmptyLocalBinds)))),
(L {A06.hs:12:3-30}
(Match
[
(L {A06.hs:12:5-10}
(ParPat
(L {A06.hs:12:6-9}
(ConPatOut
(L {A06.hs:12:7}
({abstract:ConLike}))
[]
[]
({abstract:TcEvBinds})
(InfixCon
(L {A06.hs:12:6}
(VarPat {Var: x}))
(L {A06.hs:12:8-9}
(VarPat {Var: xs}))) [a]
(WpHole))))),
(L {A06.hs:12:12}
(VarPat {Var: c}))]
(Nothing)
(GRHSs
[
(L {A06.hs:12:16-30}
(GRHS
[]
(L {A06.hs:12:16-30}
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {A06.hs:12:16-19}
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {A06.hs:12:16}
(HsVar {Var: f}))
(L {A06.hs:12:18-19}
(HsVar {Var: xs}))))))
(L {A06.hs:12:21-30}
(HsPar
(L {A06.hs:12:22-29}
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {A06.hs:12:22-27}
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {A06.hs:12:22-25}
(HsWrap
(WpCompose
(WpCompose
(WpCompose
(WpEvApp
(EvId {Var: $dIntegral_a1cs}))
(WpEvApp
(EvId {Var: $dNum_a1cr})))
(WpEvApp
(EvId {Var: $dNum_a1cq})))
(WpCompose
(WpCompose
(WpTyApp t)
(WpTyApp t))
(WpTyApp a)))
(HsVar {Var: A06.tick})))
(L {A06.hs:12:27}
(HsVar {Var: x}))))))
(L {A06.hs:12:29}
(HsVar {Var: c}))))))))))))))]
(EmptyLocalBinds))))]
[[a],(t, t)] (t, t))
(WpHole) {!NameSet placeholder here!}
(Nothing))))])))),
((,)
(FromSource)
(L {A06.hs:9:3-55}
(AbsBinds
[]
[]
[
(ABE {Var: A06.main} {Var: main}
(WpHole)
(SpecPrags
[]))]
({abstract:TcEvBinds})
({abstract:Bag((Origin,(GenLocated SrcSpan (HsBindLR Var Var))))}
[
((,)
(FromSource)
(L {A06.hs:9:3-55}
(FunBind
(L {A06.hs:9:3-6} {Var: main})
(False)
(MG
[
(L {A06.hs:9:3-55}
(Match
[]
(Nothing)
(GRHSs
[
(L {A06.hs:9:10-55}
(GRHS
[]
(L {A06.hs:9:10-55}
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {A06.hs:9:10-17}
(HsWrap
(WpTyApp (GHC.Types.Int, GHC.Types.Int))
(HsVar {Var: GHC.IO.evaluate})))
(L {A06.hs:9:19-55}
(HsPar
(L {A06.hs:9:20-54}
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {A06.hs:9:20-33}
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {A06.hs:9:20}
(HsWrap
(WpCompose
(WpCompose
(WpCompose
(WpEvApp
(EvId {Var: $dIntegral_a1d5}))
(WpEvApp
(EvId {Var: $dNum_a1d4})))
(WpEvApp
(EvId {Var: $dNum_a1d3})))
(WpCompose
(WpCompose
(WpTyApp GHC.Types.Int)
(WpTyApp GHC.Types.Int))
(WpTyApp GHC.Integer.Type.Integer)))
(HsVar {Var: A06.f})))
(L {A06.hs:9:22-33}
(ArithSeq
(HsWrap
(WpCompose
(WpEvApp
(EvId {Var: $dEnum_a1da}))
(WpTyApp GHC.Integer.Type.Integer))
(HsVar {Var: GHC.Enum.enumFromTo}))
(Nothing)
(FromTo
(L {A06.hs:9:23}
(HsOverLit
(OverLit
(HsIntegral
(1))
(False)
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {<no location info>}
(HsWrap
(WpCompose
(WpEvApp
(EvId {Var: $dNum_a1d7}))
(WpTyApp GHC.Integer.Type.Integer))
(HsVar {Var: GHC.Num.fromInteger})))
(L {<no location info>}
(HsLit
(HsInteger
(1) GHC.Integer.Type.Integer)))))) GHC.Integer.Type.Integer)))
(L {A06.hs:9:26-32}
(HsOverLit
(OverLit
(HsIntegral
(4000000))
(False)
(HsApp
(L {<no location info>}
(HsVar {Var: GHC.Num.fromInteger}))
(L {<no location info>}
(HsApp
(L {<no location info>}
(HsWrap
(WpCompose
(WpEvApp
(EvId {Var: $dNum_a1d9}))
(WpTyApp GHC.Integer.Type.Integer))
(HsVar {Var: GHC.Num.fromInteger})))
(L {<no location info>}
(HsLit
(HsInteger
(4000000) GHC.Integer.Type.Integer)))))) GHC.Integer.Type.Integer))))))))))
(L {A06.hs:9:35-54}
(ExplicitTuple
[
(Present
(L {A06.hs:9:36-43}
(ExprWithTySigOut
(L {A06.hs:9:36}
(HsOverLit
(OverLit
(HsIntegral
(0))
(False)
(HsLit
(HsInt
(0))) GHC.Types.Int)))
(L {A06.hs:9:41-43}
(HsTyVar {Name: GHC.Types.Int}))))),
(Present
(L {A06.hs:9:46-53}
(ExprWithTySigOut
(L {A06.hs:9:46}
(HsOverLit
(OverLit
(HsIntegral
(1))
(False)
(HsLit
(HsInt
(1))) GHC.Types.Int)))
(L {A06.hs:9:51-53}
(HsTyVar {Name: GHC.Types.Int})))))]
(Boxed)))))))))))))))]
(EmptyLocalBinds))))]
[] GHC.Types.IO (GHC.Types.Int, GHC.Types.Int))
(WpHole) {!NameSet placeholder here!}
(Nothing))))]))))])