Inspecting reduced/optimized code
Is it possible/easy in any of the compilers/interpreters to see what the results of rewriting/optimisations are? (I'm sure it is *possible*, I'm really asking if any produce simple output in a well documented format that I'm likely to understand). The reason I ask is because I'm curious whether the "well known" fold (foldr) (I don't have it to hand, but it's something like fold (\x g -> \n -> g x n) id) that is equivalent to foldl generates the same code as foldl itself (ie defined recursively). I know I can do timing, or look at the C code from GHC, which would tell me whether they are identical, I guess, but I was hoping for something higher level (I suupose transformed Haskell code is too much to ask for?). Should I be looking at some kind of debugging tool (never used a debugger in Haskell)? Thanks, Andrew PS Despite its sweet naivete, this post comes from a balding middle aged programmer looking for something to relieve the tedium of working shifts away from home, and not some grasping, lazy, evil student that wants to save time on homework to indulge in yet more wild, drunken orgies [sighs wistfully, looks at clock, gets back to work...]. -- http://www.acooke.org/andrew
Is it possible/easy in any of the compilers/interpreters to see what the results of rewriting/optimisations are? (I'm sure it is *possible*, I'm really asking if any produce simple output in a well documented format that I'm likely to understand).
Very easy in GHC. GHC does its optimisations on code in a functional language called "Core", which is a cut-down version of Haskell with explicit typing. It's quite readable (apart from the weird automatically-chosen variable names), and you can get it to dump it at various stages. Take a look at http://www.haskell.org/ghc/docs/latest/html/users_guide/options-debugging.ht... for info. You might find the following link useful for understanding what the various passes are: http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/ HTH. --KW 8-)
participants (2)
-
andrew cooke -
Keith Wansbrough