我有以下程序:
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
我想从 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
我能得到的最好的结果是
ghci -ddump-simpl -dsuppress-module-prefixes -dsuppress-uniques foo.hs
但是它需要大量手动删除 GHC 生成的内容才能获得上面的代码。是否有 GHC 或第三方脚本的开关可以进行清理?
有没有办法至少摆脱 case {tick (main:Main, 8)} @ (State# RealWorld) of _ { __DEFAULT ->
?
最佳答案
你很幸运!有一个工具可以完成这项工作:ghc-core .
ghc-core 用命令行包装器包装 ghc,在分页器中以人类可读的彩色方式显示 GHC 的优化核心和汇编输出。
用法 - 只需将 ghc
替换为 ghc-core
:
ghc-core A.hs
ghc-core -fvia-C -optc-O3 A.hs
关于haskell - 如何以人类可读的形式转储 GHC 简化器输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10693638/