我有以下程序:
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 ->
?