3 ms·
It's possible to write regular Haskell with semicolons and curly braces. White-space sensitivity is just a syntax sugar for that [1]. > easier to refactor and
by dmytrish 6y ago
It's possible to write regular Haskell with semicolons and curly braces. White-space sensitivity is just a syntax sugar for that [1].
> easier to refactor and automatically indent/format code.
What are the advantages of white-space insensitive code for refactoring and formatting?
[1] https://en.wikipedia.org/wiki/Haskell_features#Layout https://en.wikipedia.org/wiki/Haskell_features#Layout
- masklinn 6y ago> What are the advantages of white-space insensitive code for refactoring and formatting? For refactoring, it's less error prone when you're using an editor without refactoring support for it, would be my guess. For indent/format, your guess is as good as mine, AFAIK programs don't care whether block separators are called INDENT or {. Though the parsing of the latter would be somewhat trivially simpler as you don't need to store a stack of indent levels.
- logicchains 6y agoWith white-space insensitive code I can easily cut/paste code from one function to another, without having to potentially manually re-indent it afterwards. This makes refactoring easier. For formatting, it means I never need to manually add any spaces or tabs: the formatter always knows exactly how to indent it. With whitespace-sensitive code, I have to manually pick the indentation, as different indentations could have different semantics. That's why if I hit tab in Emacs when editing a Haskell file, it will cycle through multiple possible indentions. If I hit it in a whitespace-insensitive language, it will just move it to the "correct" indentation straight away and I don't need to worry about it. Using {} braces in Haskell seems less intuitive, at least to me. E.g. how would I use braces to avoid the need to manually indent a nested where statement?
- gnufx 6y agoI have to fix up the layout essentially manually every time I have to edit C in someone else's idea of correct layout when they haven't included C Mode rules for it. (That's assuming they want a consistent style for changes, of course.) If simplicity of parsing, and cut-and-paste are important, we should be using Lisp, of course, but there are still different indentation styles.
- frank2 6y ago>how would I use braces to avoid the need to manually indent a nested where statement? Warning: untested code main = printLn (foo * bar) where {foo = 3; bar = 4}