Re: [Haskell-cafe] accessible layout proposal?

On Sep 23, 2009, at 12:24 PM, James Hartzell wrote:
Well, look at code like this:
wrapParens str = concat [ "(", str, ")" ]
I just did. I'd write it as wrap_parens s = "(" ++ s ++ ")" although I wouldn't use that name, because it's not the parentheses that are wrapped, it's s.
First off, there is a serious issue with the commas.
You should at least be allowed to have a comma after the last element, a la Python.
Oh, I agree about that. I've written an Erlang Extension Proposal for Erlang about that.
concat [ "(", str, ")" -- (oops, no comma!) lineEnd -- forgot I needed this ]
"(" ++ str ++ ")" ++ line_end I'm actually quite serious here. Using infix ++ we have the SAME problem about missing ++ as we do about mssing , After all, someone might have started with ( "(" ++ str ++ ")" ) and ended up with ( "(" ++ str ++ ")" -- (oops, no ++!) lineEnd -- forgot I needed this ) I asked for the trailing comma in Erlang for _social_ reasons, not because I believed it would fix all problems of this type.
And as to the "simplifying your code" idea: however "pure" your code is, you will regularly have to embed lists of things in it (ADTs, export lists, data from the domain). And unless you're claiming it is *almost always bad style to have code looking like (from the proposal):
main = do a <- getChar bracket_ (enter a) (exit a) (do putChar a putStrLn "hello")
The thing about toy examples is that they are toy size. On an example this size, we don't NEED fancy new stuff. Actually, I'd write main = getChar >>= \a -> bracket_ (enter a) (exit a) (putChar a >> putStrLn "hello") so even _with_ this proposal, I'd still need exactly the same parentheses. One thing I might do is this: enter_exit_bracket a body = bracket_ (enter a) (exit a) body and then main = getChar >>= \a -> enter_exit_bracket a (putChar a >> putStrLn "hello") because it looks very much as if enter and exit exist only to be passed (with suitable parameters) to bracket_.
But I would *still* rather have: with a = bracket_ $# enter a exit a
Layout is easier to read than parentheses.
It all depends on size (small things being easy pretty much no matter what you do) and tools (tools where you click just inside parentheses and the bracketed thing lights up, like the traditional Smalltalk interface make parentheses very very easy to read).
In summary, I have to spend a good portion of my time coding Haskell dealing with the fact that I have a lot of {'s, ['s, and ,'s to keep track of, and they rarely fit on one line (records, ADTs, lists). I have to spend a significant amount of my coding time finagling the layout to look sensible, and I don't think anyone would claim that I just shouldn't use records or ADTs.
For what it's worth, the editor I normally use has an "add new element to list" command. Where I'm coming from is this: I do not find meaningless jumbles of special characters combined with overloaded white space readable. It would be so much better if we could discuss a _real_ example.

It would be so much better if we could discuss a _real_ example.
Or implement one. Unlike some proposals, this could be implemented with a preprocessor and -F -pgmF, right? As far as the parsing job, I don't know how hard this would be to plug into the haskell parsing library, but in case it is hard, then improving the library to handle layout extensions would be a nice side-effect even if the preprocessor never became widely popular.

On Sep 23, 2009, at 3:04 PM, Evan Laforge wrote:
It would be so much better if we could discuss a _real_ example.
Or implement one.
I really did mean EXAMPLES. Examples of code which would be improved *more* by the proposal than by adopting an alternative style within the existing language. Let's not forget what the proposal actually _is_. It is that "#(" "#[" "#$" and "#" should become magic tokens such that #( {a;b;c} is read as (a,b,c) #[ {a;b;c} is read as [a,b,c] f #$ {a;b;c} is read as f (a) (b) (c) # {a;b;c} is read as {a,b,c} [http://www.haskell.org/haskellwiki/Accessible_layout_proposal] Are you not troubled by the inconsistencies here? Why isn't the last case #{ to match #( and #[? Why does #$ add extra parentheses but not the others? Are you not troubled by the fact that it breaks the automatic bracket matching in editors like Vim, Emacs, XCode, ...? I _can_ hack on Emacs if I have to, but I _can't_ hack on XCode. In fact it breaks bracket matching in two ways: - clicking just after #( doesn't select the tuple the way that clicking just after ( does - the excess imbalanced bracket wrecks matching for anything that includes an #( or #[ That's a *lot* to give up for less readable code! In effect, the proposal is that there should be a context- sensitive overloading of <newline> to mean - nothing (existing case) - semicolon (existing case) - >> or >>= (existing case) - comma (for #( and #[ and #) - nothing, except parentheses magically go somewhere else That's too many overloadings for me. 'do' was already too many overloadings for me to be comfortable with, which is one reason why I avoid it. On small examples, I find no advantage. Let's see a real medium-size example. The heavy costs that I can see might just be overwhelmed by advantages in real use.
participants (2)
-
Evan Laforge
-
Richard O'Keefe