I have the following program:

data Peano = Zero | Succ Peano deriving (Show)

add Zero     b = b
add (Succ a) b = add a (Succ b)

mul Zero     b = Zero
mul (Succ a) b = add b (mul a b)

four x = let two = Succ (Succ Zero) in mul two two

I want to get something like this from GHC:

add =
  \ ds b ->
    case ds of
      Zero ->
        b
      Succ a ->
        add
          a
          (Succ b)

mul =
  \ ds b ->
    case ds of 
      Zero ->
        Zero
      Succ a ->
        add
          b
          (mul a b)

four =
    let
      two =
        Succ
           (Succ Zero)
    in
    mul two two

The best I managed to get is

ghci -ddump-simpl -dsuppress-module-prefixes -dsuppress-uniques foo.hs

but it steel required a lot of manual removal of GHC generated stuff to get the code above. Is there a switch for GHC or a third party script that does the cleanup?

Is there a way at least to get rid of case {tick (main:Main, 8)} @ (State# RealWorld) of _ { __DEFAULT ->?

share|improve this question
    
The tick annotations are generated by HPC, so disabling it should get rid of them, I think. – Peter Wortmann May 22 '12 at 9:44
    
I don't know how. I didn't turn it on - see the command line. – nponeccop May 22 '12 at 10:36
up vote 16 down vote accepted

You're in luck! There is a tool for the job: ghc-core.

ghc-core wraps ghc with a command line wrapper that displays GHC's optimised core and assembly output in a human readable, colourised manner, in a pager.

Usage - just replace ghc with ghc-core:

   ghc-core A.hs  

   ghc-core -fvia-C -optc-O3 A.hs
share|improve this answer
    
(That said, you're not going to get it more readable than this. Also, install ghc-core with cabal install ghc-core.) – Louis Wasserman May 21 '12 at 23:26
    
The screenshot link is broken. – pat May 22 '12 at 6:58
    
Unfortunately, I can't do much about that. – Don Stewart May 22 '12 at 11:41
5  
What if I am building my program using cabal? Can I still use ghc-core somehow? – Jan Stolarek Oct 19 '12 at 8:02
    
I think it should now be ghc-core -- -optc-O3 A.hs instead. – Erik Allik Mar 22 '15 at 8:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.