由于缩进而调试显式字符

问题描述 投票:5回答:1

由于压痕,Haskell automatically inserts分号和括号。在this answer中,类型错误用于让ghci用明确显示的分号和大括号打印代码。如何在没有错误的情况下查看这些插入后的代码?我希望应该有像gcc-E标志,它显示宏预处理后的代码。

haskell syntax indentation ghc
1个回答
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"#)

我怀疑你的味道有点过于扩大,但它肯定不再有块压痕了。

© www.soinside.com 2019 - 2024. All rights reserved.