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.
$ 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With