
longFunctionName various and sundry arguments | guard1 = body1 | guard2 = body2 | ... where declarations That is, with guards and where clauses indented to the same level as
Greetings, I wish to be able to indent my code like so: the function name. This seems like a perfectly reasonable indentation style to me. It also happens to be the preferred style in Clean, another layout-sensitive functional language. I believe it is not uncommon in ML dialects as well. So why is it that I'm not allowed to use it in Haskell?

On Thu, Jul 26, 2007 at 02:56:57PM -0400, anon wrote:
longFunctionName various and sundry arguments | guard1 = body1 | guard2 = body2 | ... where declarations That is, with guards and where clauses indented to the same level as
Greetings, I wish to be able to indent my code like so: the function name.
This seems like a perfectly reasonable indentation style to me. It also happens to be the preferred style in Clean, another layout-sensitive functional language. I believe it is not uncommon in ML dialects as well. So why is it that I'm not allowed to use it in Haskell?
Because in Haskell everything that is lined up is a new logical line. Haskell requires all continuation lines to be indented: longFunctonName various and sundry arguments | guard1 = body1 | guard2 = body2 | .. where declarations As for "why", it's just a matter of Haskell Committee taste. Nothing too deep, just an arbitrary set of rules. Stefan

A bandaid suggestion:
longFunctionName various and sundry arguments = f where
f | guard1 = body1
f | guard2 = body2
| ...
where declarations
(Disclaimer: untested)
As I understand it, there can be guards on the definition of f even if
it takes no arguments. Those guards can reference your the various and
sundry arguments.
On 7/26/07, Stefan O'Rear
On Thu, Jul 26, 2007 at 02:56:57PM -0400, anon wrote:
longFunctionName various and sundry arguments | guard1 = body1 | guard2 = body2 | ... where declarations That is, with guards and where clauses indented to the same level as
Greetings, I wish to be able to indent my code like so: the function name.
This seems like a perfectly reasonable indentation style to me. It also happens to be the preferred style in Clean, another layout-sensitive functional language. I believe it is not uncommon in ML dialects as well. So why is it that I'm not allowed to use it in Haskell?
Because in Haskell everything that is lined up is a new logical line. Haskell requires all continuation lines to be indented:
longFunctonName various and sundry arguments | guard1 = body1 | guard2 = body2 | .. where declarations
As for "why", it's just a matter of Haskell Committee taste. Nothing too deep, just an arbitrary set of rules.
Stefan
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFGqPS5FBz7OZ2P+dIRAgwbAKCl3ssl6X42VqSZJnhgKVH7WSzRXwCaA3x5 Ze0lGvx17IDrFXxBEvVxGeI= =5/To -----END PGP SIGNATURE-----
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, Jul 26, 2007 at 02:58:21PM -0500, Nicolas Frisby wrote:
A bandaid suggestion:
longFunctionName various and sundry arguments = f where f | guard1 = body1 f | guard2 = body2 | ... where declarations
(Disclaimer: untested)
As I understand it, there can be guards on the definition of f even if it takes no arguments. Those guards can reference your the various and sundry arguments.
Eh? Mine doesn't use up a where clause and doesn't use a f noise symbol. Why do you need a band-aid? "longFunctionName\32=\n\32|\32guard\32=\32body\n\32|\32guard\32=\32body\n\32..." Stefan

Whoops, read too fast. Sorry for the noise.
On 7/26/07, Stefan O'Rear
On Thu, Jul 26, 2007 at 02:58:21PM -0500, Nicolas Frisby wrote:
A bandaid suggestion:
longFunctionName various and sundry arguments = f where f | guard1 = body1 f | guard2 = body2 | ... where declarations
(Disclaimer: untested)
As I understand it, there can be guards on the definition of f even if it takes no arguments. Those guards can reference your the various and sundry arguments.
Eh? Mine doesn't use up a where clause and doesn't use a f noise symbol. Why do you need a band-aid?
"longFunctionName\32=\n\32|\32guard\32=\32body\n\32|\32guard\32=\32body\n\32..."
Stefan
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFGqP3jFBz7OZ2P+dIRAgGhAKC3X7hV/vLElQelqCtjZ7XlZQDvdACfftJc R2g03ScWG33jSzGJ8yxJvUM= =rq9Y -----END PGP SIGNATURE-----

2007/7/26, Stefan O'Rear
As for "why", it's just a matter of Haskell Committee taste. Nothing too deep, just an arbitrary set of rules. That's not much of an explanation, is it? I imagine someone must have given the matter some thought before describing the layout rule in great details in the language report. Perhaps there was a perfectly good reason to preclude this kind of code, but I'm afraid I do need a reason if I am to understand why. And if it turns out that there really is no such reason, would it be terribly presumptuous of me to suggest that the rules be changed to accomodate this particular style in Haskell' or a future revision of the language? I guess it would, but one can always hope.

On Thu, Jul 26, 2007 at 05:34:32PM -0400, anon wrote:
2007/7/26, Stefan O'Rear
: As for "why", it's just a matter of Haskell Committee taste. Nothing too deep, just an arbitrary set of rules. That's not much of an explanation, is it? I imagine someone must have given the matter some thought before describing the layout rule in great details in the language report. Perhaps there was a perfectly good reason to preclude this kind of code, but I'm afraid I do need a reason if I am to understand why. And if it turns out that there really is no such reason, would it be terribly presumptuous of me to suggest that the rules be changed to accomodate this particular style in Haskell' or a future revision of the language? I guess it would, but one can always hope.
Why do you think it should be allowed? The current rules are arbitrary, but they are quite simple; we don't want to add an ad-hoc exception just for this. Out of curiousity, what do you find objectionable about (legal): function argument argument2 | guard = body | guard = body as compared to (currently illegal): function argument argument2 | guard = body | guard = body Stefan

Hi
Why do you think it should be allowed? The current rules are arbitrary, but they are quite simple; we don't want to add an ad-hoc exception just for this.
The current rules are already quite complex, I believe there is some thought being given as to how to simplify them.
Out of curiousity, what do you find objectionable about (legal):
function argument argument2 | guard = body | guard = body
as compared to (currently illegal):
function argument argument2 | guard = body | guard = body
Personally, I have no problem with the current way (and would consider anything other than 4 leading spaces in the first example to be evil). However, if you are using a text editor which doesn't automatically indent the start of following lines, it might be a bit more annoying. Of course, if your editor is that bad you should consider changing to virtually anything which isn't notepad. Thanks Neil

On 7/27/07, Neil Mitchell
Personally, I have no problem with the current way (and would consider anything other than 4 leading spaces in the first example to be evil). However, if you are using a text editor which doesn't automatically indent the start of following lines, it might be a bit more annoying. Of course, if your editor is that bad you should consider changing to virtually anything which isn't notepad.
Or pico. :-) You'd be amazed the number of undergraduates I taught who refused to learn to use gvim, emacs, or any other *programming* editor, and instead spent 75% of their time battling the editor. <sigh> I must say, I agree about the indentation question. My experience is that if you use 4 space indentation and run out of columns, then it's time to refactor, and think more about how your logical structure is working (you may recall, this list recently introduced me to the Maybe monad transformer for exactly this reason). It's actually a pretty effective rule of thumb. cheers, T. -- Dr Thomas Conway drtomc@gmail.com Silence is the perfectest herald of joy: I were but little happy, if I could say how much.

2007/7/26, Stefan O'Rear
Out of curiousity, what do you find objectionable about (legal):
function argument argument2 | guard = body | guard = body
as compared to (currently illegal):
function argument argument2 | guard = body | guard = body
The extra space, obviously :-) I'm well aware that this is an issue of vanishingly small consequence, but one could likewise dismiss the entire layout business as a needlessly complicated way to save a few keystrokes if one were so inclined. If language complexity is the chief concern, why not dispense with layout altogether (and a few more things beside)? Perhaps fuzzy notions of aesthetics and intuitiveness should weigh into the equation as well unless you don't mind programming in the unadorned lambda calculus.

On Thu, Jul 26, 2007 at 08:17:06PM -0400, anon wrote:
2007/7/26, Stefan O'Rear
: Out of curiousity, what do you find objectionable about (legal):
function argument argument2 | guard = body | guard = body
as compared to (currently illegal):
function argument argument2 | guard = body | guard = body
The extra space, obviously :-) I'm well aware that this is an issue of vanishingly small consequence, but one could likewise dismiss the entire layout business as a needlessly complicated way to save a few keystrokes if one were so inclined. If language complexity is the chief concern, why not dispense with layout altogether (and a few more things beside)? Perhaps fuzzy notions of aesthetics and intuitiveness should weigh into the equation as well unless you don't mind programming in the unadorned lambda calculus.
Definitely, and Haskell *was* designed to be aesthetic. I suppose what I'm really trying to ask is *why* you think the second should be legal. To me it just seems like an ugly ad-hoc generalization, and ad-hoc generalizations are something Haskell tries to avoid. (There's a bit of background on the syntax design process in SPJ's History of Haskell paper, page 10 of http://research.microsoft.com/~simonpj/papers/history-of-haskell/history.pdf). Stefan

Concerning
function argument argument2 | guard = body | guard = body
I feel that anything that prevents that kind of horror is a great benefit of the current rules and that this benefit must not be lost by any revision of the rules. The Fundamental Law of Indentation is "If major syntactic unit X is a proper part of major syntactic unit Y, then every visible character of X is strictly to the right[%] of the leftmost[%] visible character of Y." [%] If you are using a right-to-left script, switch "left" and "right" in that sentence. That is how indentation makes structure visible, and if you break that, you just plain aren't indenting. This isn't fuzzy, and it isn't aesthetic, it's simply that if you start things in the same column you are making it obvious to the reader than neither is part of the other. In the example about, that's not true. You might as well go around ending sentences with

2007/7/26, ok
The Fundamental Law of Indentation is "If major syntactic unit X is a proper part of major syntactic unit Y, then every visible character of X is strictly to the right[%] of the leftmost[%] visible character of Y." [%] If you are using a right-to-left script, switch "left" and "right" in that sentence.
What makes this a law? If you notice a pattern where beginners trip against this rule because they don't indent the arms of conditionals properly inside do blocks, should strict adherence to this principle take precendence over the intuition of prospective users of the language? Oddly enough, members of the Haskell' committee seem to think we should amend the rules for the benefit of programmers rather the other way around, but I guess they never heard of the Fundamental Law of Indentation.
That is how indentation makes structure visible, and if you break that, you just plain aren't indenting. This isn't fuzzy, and it isn't aesthetic, it's simply that if you start things in the same column you are making it obvious to the reader than neither is part of the other. In the example about, that's not true. You might as well go around ending sentences with
I see what you did there. But you really might as well end sentences with prepositions. Or begin them with conjunction. Or indent your code whichever way seems most natural and elegant because to do otherwise is just prescriptivism for its own sake. In general, people don't much care for arbitrary rules; they like to understand the rationale behind them before they get on board, which is all I'm really asking for here.

On 27/07/07, anon
I see what you did there. But you really might as well end sentences with prepositions. Or begin them with conjunction. Or indent your code whichever way seems most natural and elegant because to do otherwise is just prescriptivism for its own sake.
Natural and artificial languages cannot be compared on this level. Programming languages, and Haskell in particular, are nearly entirely prescriptive. In fact, if I remember rightly Haskell was originally intended to be more prescriptive than most. It certainly has fewer "nasal demon" clauses in the Haskell Report. This differs a great deal from English, for example, which underwent a slow and undirected evolution (unless there was an English Committee in 1550 set up to decide the Great Vowel Problem...) from various parent languages, themselves not designed either. If you would *like* to use an arbitrary indentation I think unsugared Haskell should allow that. Though it seems rather an uncomfortable hair-shirt to wear for such little reward. Cheers, D.

On Fri, 27 Jul 2007 00:33:17 -0400, you wrote:
What makes this a law? If you notice a pattern where beginners trip against this rule because they don't indent the arms of conditionals properly inside do blocks, should strict adherence to this principle take precendence over the intuition of prospective users of the language?
What exactly are you proposing as an alternative rule? If you're suggesting that _any_ line at the same level of indentation as the previous line be treated as a continuation of that line, then how would one go about indicating that a line is _not_ a continuation of the previous line? On the other hand, if you're suggesting that only certain things be recognized as being a continuation of the previous line (e.g., guard clauses), then it seems to me that you're replacing a brain-dead simple and straightforward rule with one that is inherently more complex and thus more likely to cause angst among beginners. Or are you proposing to get rid of layout altogether and rely on punctuation? I just can't think of a rule that would be easier to understand (and quicker to assimilate) than the current one. Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/

What exactly are you proposing as an alternative rule? If you're suggesting that _any_ line at the same level of indentation as the previous line be treated as a continuation of that line, then how would one go about indicating that a line is _not_ a continuation of the previous line? I don't see any fundamental reason why this couldn't be handled like
On the other hand, if you're suggesting that only certain things be recognized as being a continuation of the previous line (e.g., guard clauses), then it seems to me that you're replacing a brain-dead simple and straightforward rule with one that is inherently more complex and thus more likely to cause angst among beginners. For the most part, beginners can get by using only a superficial understanding of the layout rule. They only have to worry about the
2007/7/27, Steve Schafer
if condition then consequent else alternative which works well enough until you try to use it inside a do block. Amending the rules to allow this usage would arguably decrease "angst among beginners" with no appreciable impact on the overall complexity of the language. I see my original example as belonging to this same category of sensible things that are disallowed for no apparent reason.
Or are you proposing to get rid of layout altogether and rely on punctuation?
I just can't think of a rule that would be easier to understand (and quicker to assimilate) than the current one. Clearly, eliminating layout altogether would simplify things greatly. And yet, I assume would do want to keep it around even at the cost of increased complexity. Why is that I wonder? What is far less clear however is that adding a few optional semicolons to the grammar in order to accommodate different programming styles would impose an incommensurate intellectual burden on programmers who paradoxically don't mind the occasional detour through category theory in their "hello world" programs.

On 27 Jul 2007, at 4:33 pm, anon wrote:
2007/7/26, ok
: The Fundamental Law of Indentation is "If major syntactic unit X is a proper part of major syntactic unit Y, then every visible character of X is strictly to the right[%] of the leftmost[%] visible character of Y." [%] If you are using a right-to-left script, switch "left" and "right" in that sentence.
What makes this a law
Logical necessity. That is simply what indentation *IS*. That's what it *means* to indent something to show its structure.
If you notice a pattern where beginners trip against this rule because they don't indent the arms of conditionals properly inside do blocks, should strict adherence to this principle take precendence over the intuition of prospective users of the language?
The beginners I have taught Haskell to over the last five or six years have made many mistakes, but that particular one has never been a problem for them. Mind you, that may be because I teach them "don't use 'do' (yet)". While they haven't had any problem with 'if' inside 'do', those of my students who have found 'do' in their textbook and decided to use it have repeatedly run into enormous semantic problems. In particular, pat <- expr LOOKS like an assignment, so they mistakenly expect it to ACT like an assignment. It seems clear, therefore, that the heart of the problem is not the indentation rules, but 'do' in and of itself. Rather than amend the rules, it would be better *for beginners* if 'do' were not in the language at all. Should strict adherence to an indentation principle take precedence over "intuition"? Yes, YES, *YES*, ten thousand times YES. Your "intuition" is my "hopeless obscurity".

On the topic of indenting, it would be nice if there was a way to tell the compiler the size of the tab characters. The way it is now, I have to use space characters to indent. It's not really a problem though.

On Wed, 2007-08-01 at 16:05 +0200, david48 wrote:
On the topic of indenting, it would be nice if there was a way to tell the compiler the size of the tab characters.
The way it is now, I have to use space characters to indent.
Good! You're doing exactly the right thing according to the Haskell style guide: http://urchin.earth.li/~ian/style/haskell.html :-) Duncan

On Aug 1, 2007, at 10:05 , david48 wrote:
On the topic of indenting, it would be nice if there was a way to tell the compiler the size of the tab characters.
The way it is now, I have to use space characters to indent.
The problem with that is, while there's a standard for the width of a tab on Unix, there isn't on Windows. It's really only safe to use spaces for indentation. Thus, it's better to use an editor which converts tabs to spaces in a specified manner, so you can use whatever tabs you're comfortable with (or none; Emacs generally uses tab to mean "indent appropriately") but the resulting file uses spaces and will behave reliably anywhere. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On 8/1/07, Brandon S. Allbery KF8NH
On Aug 1, 2007, at 10:05 , david48 wrote:
On the topic of indenting, it would be nice if there was a way to tell the compiler the size of the tab characters.
The way it is now, I have to use space characters to indent.
The problem with that is, while there's a standard for the width of a tab on Unix, there isn't on Windows. It's really only safe to use spaces for indentation.
On second thought, I don't even know why I posted this. There's so many things far more important that tabs, and using spaces is truly the only safe way. Sorry for the noise.

On Thu, Jul 26, 2007 at 08:17:06PM -0400, anon wrote:
but one could likewise dismiss the entire layout business as a needlessly complicated way to save a few keystrokes if one were so inclined.
The main point of layout, in my eyes, is to make code more readable. It achieves this both by removing noise (i.e. {;}) and by forcing you to align your code so it is clear (or at least clear/er/) what is going on. It's also important that the rules are easily understood by programmers, and easily implemented by Haskell implementations and tools. The current rules aren't perfect. For example, they fail the last point. I thought there was a Haskell' ticket about that, but I can't see it now. Thanks Ian

On Thursday 26 July 2007, anon wrote:
2007/7/26, Stefan O'Rear
: Out of curiousity, what do you find objectionable about (legal):
function argument argument2
| guard = body | guard = body
as compared to (currently illegal):
function argument argument2
| guard = body | guard = body
The extra space, obviously :-) I'm well aware that this is an issue of vanishingly small consequence, but one could likewise dismiss the entire layout business as a needlessly complicated way to save a few keystrokes
On the contrary. Layout, by itself, strictly reduces the number of ways to write any given program. It makes things more consistent across coding styles. That's not an inconsequential benefit.
if one were so inclined. If language complexity is the chief concern, why not dispense with layout altogether (and a few more things beside)? Perhaps fuzzy notions of aesthetics and intuitiveness should weigh into the equation as well unless you don't mind programming in the unadorned lambda calculus.
Jonathan Cast http://sourceforge.net/projects/fid-core http://sourceforge.net/projects/fid-emacs

Stefan O'Rear wrote:
Out of curiousity, what do you find objectionable about (legal):
function argument argument2 | guard = body | guard = body
as compared to (currently illegal):
function argument argument2 | guard = body | guard = body
I see the vertical strokes as visually lining up, pointing at something. In the legal example, they are pointing to the second character of the function name, wich has no meaning, but in the currently illegal example, they are pointing to the function name as a whole, wich has a meaning: To see wich function we are defining here, follow the vertical strokes upwards. (I don't need the strokes to show me that, of course, I just don't want them to distract me by pointing at a random position). As I understand it, the idea behind layout is to use indention to express tree-like structures in plain text: root first level node second level node another second level node another first level node second level node in a different subtree This is fine as long as no vertical strokes show up at the beginning of lines, since vertical strokes are sometimes used to express tree-like structures in plain text, too: root | first level | | second level | | another second level node | another first level node | | second level node in a different subtree The plain text parser embedded into my eyes seems to expect something like the latter tree encoding when it sees vertical strokes at the beginning of lines, but Haskell layout works more like the former. To help my eyes, I try to write the whole pattern in a single line. function argument argument2 | guard1 = body1 | guard2 = body2 If lines get too long this way, I wrap the body, not the pattern: function argument argument2 | guard1 = body1 function argument argument2 | guard2 = body2 Of course, if I want to have local definitions visible to both bodies, I have to write something like this: function argument argument2 = result where result | guard1 = body1 result | guard2 = body2 helper = ... other_stuff = ... I don't think this is a layout problem, I think this is a pattern syntax problem. (Or it may be a problem of my eyes). As I understand it, the layout rule is not made for stuff starting with keywords, but for stuff starting with identifiers, to avoid having to use keywords. But "|" is clearly a keyword here. So if I were to design it, I would try to get rid of the repeated "|" keyword, maybe allowing the running example to be written as function argument argument2 | guard1 = body1 guard2 = body2 wich seems to be much clearer for my eyes. Another option would be function argument argument2 = guard1 -> body1 | guard2 -> body2 wich is good because "|" now works like in data defintions, meaning "alternatively", but bad because the "pattern matching stops when crossing the equals sign"-rule no longer holds. Tillmann

On Thu, Jul 26, 2007 at 05:34:32PM -0400, anon wrote:
2007/7/26, Stefan O'Rear
: As for "why", it's just a matter of Haskell Committee taste. Nothing too deep, just an arbitrary set of rules. That's not much of an explanation, is it? I imagine someone must have given the matter some thought before describing the layout rule in great details in the language report. Perhaps there was a perfectly good reason to preclude this kind of code, but I'm afraid I do need a reason if I am to understand why.
Part of the reason is that the layout rule is supposed to be somewhat independent of the rest of the grammar. It's described as a simple preprocessing state that adds block delimiters { ; } just recongizing a few keywords that open blocks, and otherwise looking at the indentation of the first non-whitespace character on lines. You can allow the syntaxes where something is no less indented than it's containing block by allowing some optional semicolons in the grammar. GHC keeps it's parser in compiler/parser/Parser.y.pp It's a Happy grammar file, it shouldn't be hard to make your change and see how you like it. I think the "gdrh" nonterminal is the one you want to change, add another production that allows ';' '|' quals '=' exp Have fun Brandon Moore

longFunctionName various and sundry arguments | guard1 = body1 | guard2 = body2 | ... where declarations That is, with guards and where clauses indented to the same level as
I wish to be able to indent my code like so: the function name.
Sounds like a generalization of the idea of allowing indentation like if foo then bar else baz in `do' notation. It might probably be obtained similarly by just adding a few optional semi-colons at the right place in the BNF rules. whether those optional semi-colons will render the grammar significantly more complex, I don't know. Stefan
participants (16)
-
anon
-
Brandon Michael Moore
-
Brandon S. Allbery KF8NH
-
david48
-
Dougal Stanton
-
Duncan Coutts
-
Ian Lynagh
-
Jonathan Cast
-
Neil Mitchell
-
Nicolas Frisby
-
ok
-
Stefan Monnier
-
Stefan O'Rear
-
Steve Schafer
-
Thomas Conway
-
Tillmann Rendel