Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug explicit characters due to indentation

Haskell automatically inserts semicolons and braces due to indentation. In this answer, a type error is used to have ghci print the code with the semicolons and braces explicitly shown. How can I view code after these insertions without an error? I expect there should be something like gcc's -E flag, which shows code after macro preprocessing.

like image 371
Matt Joiner Avatar asked Mar 03 '18 05:03

Matt Joiner


1 Answers

$ 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"#)

I suspect that's a bit too expanded for your taste, but it certainly doesn't have the block-indentation anymore.

like image 93
leftaroundabout Avatar answered Sep 30 '22 13:09

leftaroundabout