I cant seem to find much info on haskells layout features, as I understand it is something like pythons formatting requirements except that is optional. How can I choose not to use this option correctly? Would it be a good idea to start without it so that I get a solid feel for the language itself?
views:
276answers:
2See http://en.wikibooks.org/wiki/Programming:Haskell_indentation and http://www.haskell.org/onlinereport/lexemes.html#sect2.7 (both contain examples).
Pros:
- less typing
- less to read, nicer-looking (if you're comfortable with it)
Cons:
- you might get it wrong, especially if you're not familiar with it. Braces make things crystal clear if you're not sure.
Haskell's layout is one of its defining features, imho. Part of the entire philosophy of Haskell is that it is more math-like. And using layout is a huge step towards that. For many programs, if you were to write pseudo-code out of math equations, it would end up being valid Haskell syntax using layout. I highly recommend at least trying layout.
The downside is that subtle indentation errors can arise. This can be frustrating at first, esp. if you're not familiar with it. But the compiler tells you about them. Once you fix it, you're left with code that is often very pleasant to look at.
You can not use it simply by using curly braces for explicit blocks and semicolons for separators.