由于缩进而调试显式字符

时间:2018-03-03 05:53:26

标签: haskell syntax indentation ghc

由于缩进,Haskell automatically inserts分号和括号。在this answer中,类型错误用于ghci使用分号和括号显式显示代码。如何在没有错误的情况下查看这些插入后的代码?我希望应该有gcc的{​​{1}}标志,它会在宏预处理后显示代码。

1 个答案:

答案 0 :(得分:2)

$ cat >> Hello.hs
main = do
    putStr "Hello, "
    putStrLn "World!"

$ ghc -ddump-ds Hello.hs   # ds for "desugar"
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )

==================== Desugar (after optimization) ====================
Result size of Desugar (after optimization)
  = {terms: 18, types: 9, coercions: 0, joins: 0/0}

-- RHS size: {terms: 8, types: 3, coercions: 0, joins: 0/0}
main :: IO ()
[LclIdX]
main
  = >>
      @ IO
      GHC.Base.$fMonadIO
      @ ()
      @ ()
      (putStr (GHC.CString.unpackCString# "Hello, "#))
      (putStrLn (GHC.CString.unpackCString# "World!"#))

-- RHS size: {terms: 2, types: 1, coercions: 0, joins: 0/0}
:Main.main :: IO ()
[LclIdX]
:Main.main = GHC.TopHandler.runMainIO @ () main

-- RHS size: {terms: 5, types: 0, coercions: 0, joins: 0/0}
Main.$trModule :: GHC.Types.Module
[LclIdX]
Main.$trModule
  = GHC.Types.Module
      (GHC.Types.TrNameS "main"#) (GHC.Types.TrNameS "Main"#)

我怀疑你的口味有点,但它肯定不会有块缩进。