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 AST

(printForUser dflags stdout unqual . shown TypeChecker) typechecked

{Bag(Located (HsBind Var)): 
[
 (L {A06.hs:(14,3)-(15,44)} 
  (AbsBinds 
   [{Var: a},{Var: t},{Var: t}] 
   [{Var: $dIntegral},{Var: $dNum},{Var: $dNum}] 
   [
    (ABE {Var: A06.tick} {Var: tick} 
     (WpCompose 
      (WpCompose 
       (WpCompose 
        (WpCompose 
         (WpTyLam {Var: a}) 
         (WpCompose 
          (WpTyLam {Var: t}) 
          (WpTyLam {Var: t}))) 
        (WpCompose 
         (WpEvLam {Var: $dIntegral}) 
         (WpCompose 
          (WpEvLam {Var: $dNum}) 
          (WpEvLam {Var: $dNum})))) 
       (WpLet 
        ({abstract:TcEvBinds}))) 
      (WpCompose 
       (WpCompose 
        (WpCompose 
         (WpEvApp 
          (EvId {Var: $dNum})) 
         (WpEvApp 
          (EvId {Var: $dNum}))) 
        (WpEvApp 
         (EvId {Var: $dIntegral}))) 
       (WpCompose 
        (WpCompose 
         (WpTyApp t) 
         (WpTyApp t)) 
        (WpTyApp a)))) 
     (SpecPrags 
      []))] 
   ({abstract:TcEvBinds}) {Bag(Located (HsBind Var)): 
   [
    (L {A06.hs:(14,3)-(15,44)} 
     (FunBind 
      (L {A06.hs:14:3-6} {Var: tick}) 
      (False) 
      (MatchGroup 
       [
        (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} 
                (ExprStmt 
                 (L {A06.hs:14:21-26} 
                  (HsApp 
                   (L {A06.hs:14:21-24} 
                    (HsWrap 
                     (WpCompose 
                      (WpEvApp 
                       (EvId {Var: $dIntegral})) 
                      (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})) 
                       (WpTyApp t)) 
                      (HsVar {Var: GHC.Num.+}))) {Fixity: infixl 6} 
                    (L {A06.hs:14:43} 
                     (HsOverLit 
                      (OverLit 
                       (HsIntegral 
                        (1)) 
                       (False) 
                       (HsApp 
                        (L {<no location info>} 
                         (HsWrap 
                          (WpCompose 
                           (WpEvApp 
                            (EvId {Var: $dNum})) 
                           (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} 
                (ExprStmt 
                 (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})) 
                       (WpTyApp t)) 
                      (HsVar {Var: GHC.Num.+}))) {Fixity: infixl 6} 
                    (L {A06.hs:15:39} 
                     (HsOverLit 
                      (OverLit 
                       (HsIntegral 
                        (1)) 
                       (False) 
                       (HsApp 
                        (L {<no location info>} 
                         (HsWrap 
                          (WpCompose 
                           (WpEvApp 
                            (EvId {Var: $dNum})) 
                           (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)))]})),
 (L {A06.hs:(11,3)-(12,30)} 
  (AbsBinds 
   [{Var: a},{Var: t},{Var: t}] 
   [{Var: $dIntegral},{Var: $dNum},{Var: $dNum}] 
   [
    (ABE {Var: A06.f} {Var: f} 
     (WpCompose 
      (WpCompose 
       (WpCompose 
        (WpCompose 
         (WpTyLam {Var: a}) 
         (WpCompose 
          (WpTyLam {Var: t}) 
          (WpTyLam {Var: t}))) 
        (WpCompose 
         (WpEvLam {Var: $dIntegral}) 
         (WpCompose 
          (WpEvLam {Var: $dNum}) 
          (WpEvLam {Var: $dNum})))) 
       (WpLet 
        ({abstract:TcEvBinds}))) 
      (WpCompose 
       (WpCompose 
        (WpCompose 
         (WpEvApp 
          (EvId {Var: $dNum})) 
         (WpEvApp 
          (EvId {Var: $dNum}))) 
        (WpEvApp 
         (EvId {Var: $dIntegral}))) 
       (WpCompose 
        (WpCompose 
         (WpTyApp t) 
         (WpTyApp t)) 
        (WpTyApp a)))) 
     (SpecPrags 
      []))] 
   ({abstract:TcEvBinds}) {Bag(Located (HsBind Var)): 
   [
    (L {A06.hs:(11,3)-(12,30)} 
     (FunBind 
      (L {A06.hs:11:3} {Var: f}) 
      (False) 
      (MatchGroup 
       [
        (L {A06.hs:11:3-16} 
         (Match 
          [
           (L {A06.hs:11:5-6} 
            (ConPatOut 
             (L {A06.hs:11:5-6} {DataCon: []}) 
             [] 
             [] 
             ({abstract:TcEvBinds}) 
             (PrefixCon 
              []) [a])),
           (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} {DataCon: :}) 
               [] 
               [] 
               ({abstract:TcEvBinds}) 
               (InfixCon 
                (L {A06.hs:12:6} 
                 (VarPat {Var: x})) 
                (L {A06.hs:12:8-9} 
                 (VarPat {Var: xs}))) [a])))),
           (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 {A06.hs:12:16-19} 
                 (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 {A06.hs:12:22-27} 
                     (HsApp 
                      (L {A06.hs:12:22-25} 
                       (HsWrap 
                        (WpCompose 
                         (WpCompose 
                          (WpCompose 
                           (WpEvApp 
                            (EvId {Var: $dNum})) 
                           (WpEvApp 
                            (EvId {Var: $dNum}))) 
                          (WpEvApp 
                           (EvId {Var: $dIntegral}))) 
                         (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)))]})),
 (L {A06.hs:9:3-55} 
  (AbsBinds 
   [] 
   [] 
   [
    (ABE {Var: A06.main} {Var: main} 
     (WpHole) 
     (SpecPrags 
      []))] 
   ({abstract:TcEvBinds}) {Bag(Located (HsBind Var)): 
   [
    (L {A06.hs:9:3-55} 
     (FunBind 
      (L {A06.hs:9:3-6} {Var: main}) 
      (False) 
      (MatchGroup 
       [
        (L {A06.hs:9:3-55} 
         (Match 
          [] 
          (Nothing) 
          (GRHSs 
           [
            (L {A06.hs:9:10-55} 
             (GRHS 
              [] 
              (L {A06.hs:9:10-55} 
               (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 {A06.hs:9:20-33} 
                     (HsApp 
                      (L {A06.hs:9:20} 
                       (HsWrap 
                        (WpCompose 
                         (WpCompose 
                          (WpCompose 
                           (WpEvApp 
                            (EvId {Var: $dNum})) 
                           (WpEvApp 
                            (EvId {Var: $dNum}))) 
                          (WpEvApp 
                           (EvId {Var: $dIntegral}))) 
                         (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})) 
                          (WpTyApp GHC.Integer.Type.Integer)) 
                         (HsVar {Var: GHC.Enum.enumFromTo})) 
                        (FromTo 
                         (L {A06.hs:9:23} 
                          (HsOverLit 
                           (OverLit 
                            (HsIntegral 
                             (1)) 
                            (False) 
                            (HsApp 
                             (L {<no location info>} 
                              (HsWrap 
                               (WpCompose 
                                (WpEvApp 
                                 (EvId {Var: $dNum})) 
                                (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>} 
                              (HsWrap 
                               (WpCompose 
                                (WpEvApp 
                                 (EvId {Var: $dNum})) 
                                (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)))]}))]}