4 ms·
Haskell's solution to this problem is also excellent and needs to be better known and copied into newer languages. The language has curly braces around the bod
by pklausler 11y ago
Haskell's solution to this problem is also excellent and needs to be better known and copied into newer languages. The language has curly braces around the bodies of 'let', 'case', 'where', and 'do' constructs, and also the bodies of modules, and semicolons between the constituents of those constructs -- but when the compiler demands a '{' and doesn't see one, it uses indentation to insert them in the obvious places. If your indentation is incorrect, you're likely to get an implicit ';' or '}' put in the wrong place, and you go fix it.
The scheme works so well that people will often go months into their Haskell education before they encounter code with explicit braces and semicolons.
- wyager 11y agoI've actually never seen production code with braces or semicolons. The only place it's semi-common is when people write complicated expressions and need to put them on one line for the REPL (GHCi).
- arnsholt 11y agoI think another use-case for non-layout version is generated code. If you happen to generate Haskell code, it's easier to keep the syntax correct with the explicit notation rather than the implicit whitespace version.