Wednesday, February 16, 2011

A Simple Experiment ...

or not.

One of the things I like to do when I'm getting to learn a new compiler is to take a couple of very simple programs and look at the assembly that the compiler produces.  I tried this with GHC and the following program, add.hs:

add' x y = x + y

main = do
   print $ add' 1 2

The result of  ghc -S add.hs  was 301 lines of assembly code. Adding an explicit type annotation for add' brought it down to 252 lines, and the code was still beyond my meager ability to take in assembly. 

No comments:

Post a Comment