
Hi, I understand that many people like using layout in their code, and 99% of all Haskell examples use some kind of layout rule. However, sometimes, I would like not to use layout, so I can find errors easier (and maybe convert it to layout for presentation after all problems are solved). So, I wonder: would it be possible to implement a feature in, say, ghc, that would take code from input and output the same code with layout replaced by delimiting characters? For instance, it could take (untested code warning here): main = do s <- readLn putStrLn s and convert it to: main = do {s<-readLn; putStrLn s}; I imagine that would be easy, since the compiler has to do that as a first step anyway. If it's possible, how can I sugest that feature? Thanks, Maurício

briqueabraque:
Hi,
I understand that many people like using layout in their code, and 99% of all Haskell examples use some kind of layout rule. However, sometimes, I would like not to use layout, so I can find errors easier (and maybe convert it to layout for presentation after all problems are solved).
So, I wonder: would it be possible to implement a feature in, say, ghc, that would take code from input and output the same code with layout replaced by delimiting characters? For instance, it could take (untested code warning here):
main = do s <- readLn putStrLn s
and convert it to:
main = do {s<-readLn; putStrLn s};
I imagine that would be easy, since the compiler has to do that as a first step anyway.
If it's possible, how can I sugest that feature?
ghc -ddump-parsed does this, iirc. So does the Language.Haskell library. See this wiki page on indenting for more ideas, http://haskell.org/haskellwiki/Indent -- Don

Hi,
(...)
So, I wonder: would it be possible to implement a feature in, say, ghc, that would take code from input and output the same code with layout replaced by delimiting characters? (...)
ghc -ddump-parsed does this, iirc.
So does the Language.Haskell library. See this wiki page on indenting for more ideas,
http://haskell.org/haskellwiki/Indent
-- Don
I was impressed after your tip about 'Language.Haskell'. In a few minutes, I got my dream Haskell formatter. Here it is, parsed by itself. Thanks for your tip. module Main (Main.main) where { import System.IO; import Language.Haskell.Parser; import Language.Haskell.Pretty; import Text.PrettyPrint.HughesPJ; main :: IO (); main = do { program <- getContents; ParseOk parse <- return $ parseModule program; estilo <- return $ Style PageMode 50 1.0; modo <- return $ PPHsMode 0 0 0 0 0 3 True PPSemiColon False True; putStrLn $ prettyPrintStyleMode estilo modo parse}}
participants (2)
-
Don Stewart
-
Maurício