haskell - 如何以人类可读的形式转储 GHC 简化器输出?

标签 haskell command-line ghc

我有以下程序:

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/

相关文章:

linux - 用于在文件中生成任意大小的随机内容的命令

haskell - 对HashTable的性能问题感到好奇

optimization - 幂等性的这种概括的名称是什么?

haskell - 不能使用带有haskell的glade xml文件

haskell - 帮助理解无点代码

haskell - :reload and run :main as a single command in GHCi?的正确方法是什么

haskell - 在 GHC 中禁用 "Module does not export identifier"警告

list - 在 Haskell 中表示 2D 矢量的正确方法是什么?

java - 让Java在循环之间 hibernate ,Linux上命令行指定的 hibernate 时间

SVN:如何在 Subversion 中列出更改列表中的所有文件?