News for hackers. Stuff that matters.
Re:Haskell ArgumentDo Proposal by chadaustin on Monday July 04, 2016 @07:46PM (#12033596)
People spend time on this because Haskell syntax is deeply unpleasant to a lot of people, including myself. I love the capabilities and expressiveness of Haskell, but I find the syntax annoying, and it hasn't gotten better even coming on three years of active Haskell programming.

I've forgotten the $ in some usage of do or a final argument lambda twice in the last week even.

I think it's worth solving these (superficial?) syntax issues even if they only affect the comfort of a third of all Haskell programmers.

Re:Haskell ArgumentDo Proposal by chriswarbo on Tuesday July 05, 2016 @05:12AM (#12035240)
> People spend time on this because Haskell syntax is deeply unpleasant to a lot of people, including myself.

I can understand that the syntax may be unpleasant, but I don't think having to memorise even more precedence rules makes a language more pleasant.

When I read and write Haskell, my default "mode" is to see whitespace as function application, i.e. if I see "A B" then I assume "A" is being applied to "B". Hacks like "A $ B" interfere with this, since I have to mentally back-track and re-parse them as "$ (A) (B)".

> I've forgotten the $ in some usage of do or a final argument lambda twice in the last week even.

This is exactly the kind of thing I was lamenting. Rather than (ab)using "$", why not do the more natural thing, which every other language does, and use parentheses for grouping?

Instead of "forgetting the $" in

    atomically do
          v <- readTVar tv
          writeTVar tv $! v + 1
Why not use parentheses for the job they're designed for, and write:

    atomically (do
          v <- readTVar tv
          writeTVar tv $! v + 1)
Likewise, for

    withForeignPtr fptr \ptr -> c_memcpy buf ptr size
You can use parentheses and never "forget the $"

    withForeignPtr fptr (\ptr -> c_memcpy buf ptr size)
Parentheses are a universally understood syntax for grouping, they're supported in editors (e.g. finding matching pairs, checking if they're balanced, etc.), they always work in the same way, have no interference with other constructs or edge-cases, etc.

Don't get me wrong, the "$" function is really useful, for example in "map ($ arg) [func1, func2, func3]", but I don't see the point of abusing it to avoid parentheses. I do sometimes use it myself, but whenever there are multiple infix functions around, I'll tend to use "redundant" parentheses for grouping.

Re:Haskell ArgumentDo Proposal by cousin_it on Tuesday July 05, 2016 @06:19AM (#12035451)
Syntactically significant indentation doesn't mix well with parentheses. (That's why Python doesn't have multiline lambda, for example.) And Haskell's rules for indentation are much more complicated than Python's, so the interactions with parentheses are even worse. I'm not sure there's any single person who really understands all the edge cases. It's a complete clusterfuck, they better start afresh. C-style parentheses and curly braces are so much better for parsing, copy-paste, automatically generated code, etc.
Re:Haskell ArgumentDo Proposal by chriswarbo on Tuesday July 05, 2016 @07:12AM (#12035596)
> C-style parentheses and curly braces are so much better for parsing, copy-paste, automatically generated code, etc.

Firstly, to get this out of the way, you shouldn't be using significant indentation when generating code unless you have a good reason; use parentheses, curly braces and semicolons instead https://en.wikibooks.org/wiki/Haskell/Indentation#Explicit_c...

Now, I wouldn't say parentheses and offside rules "don't mix well", but I'll grant that there are interactions to keep in mind.

It's true that Haskell's indentation edge-cases are unfathomable, although thankfully I've never run into any. I have no strong preferences either way regarding significant whitespace, as long as there's an "escape hatch" for code generation (i.e. the braces and semicolons I linked to above).

Regarding Python, its lambdas aren't "single line", they're "single expression"; that expression can cover as many lines as you like (e.g. see my SO answer http://programmers.stackexchange.com/a/252546/112115 ).

When learning Haskell, after being a long time Python programmer, I used to think Haskell's indentation rules were complicated. These days, I find it awkward to indent Python code, and end up second-guessing the interpreter a lot.

Maybe that's because I'm fond of using 2D code layout and vertical alignment to indicate relationships between lines, which is quite natural in Haskell. Python's indentation seems to be limited to counting blocks, so it's hit or miss whether adding extra spaces to align things will cause it to choke or not.

Re:Haskell ArgumentDo Proposal by cfallin on Monday July 04, 2016 @08:54PM (#12033815)
I wonder if anyone is working on a full rework of Haskell's syntax, a la Facebook's Reason for OCaml? I'm a big fan of the semantics but not as much the syntax of Haskell, too, and it would be interesting to see what a more... current-day-mainstream... syntax (Rust-like braces-and-semicolons-expression-based-language style, perhaps) would do for it.
Re:Haskell ArgumentDo Proposal by DanWaterworth on Tuesday July 05, 2016 @02:19AM (#12034710)
This is what I'm doing with plastic [1], though it also has some semantic differences: strict instead of lazy, monads become objects.

[1] https://github.com/DanielWaterworth/plastic

Re:Haskell ArgumentDo Proposal by taylorfausak on Tuesday July 05, 2016 @12:15PM (#12037472)
That doesn't compile to Haskell.
Re:Haskell ArgumentDo Proposal by DanWaterworth on Tuesday July 05, 2016 @12:30PM (#12037611)
I'm surprised that you expected it to.

edit: Having looked at Reason more closely, I now see where the confusion came from. Sorry, I didn't mean to deceive you.

Re:Haskell ArgumentDo Proposal by chriswarbo on Tuesday July 05, 2016 @04:30AM (#12035087)
There was Liskell, but unfortunately it seems to be unmaintained :(
Re:Haskell ArgumentDo Proposal by akhilcacharya on Monday July 04, 2016 @10:14PM (#12034037)
This would be absolutely amazing actually.
Re:Haskell ArgumentDo Proposal by platz on Tuesday July 05, 2016 @12:29AM (#12034403)
Wait till you see a rust-style datatype polymorphic over 4 parameters, and use that type over and over again. Haskell syntax may not make much sense coming from algol-inspired syntax, but to express its patterns it makes sense otherwise you end up with scala type lambda madness.

Both purescript and agda have this

Re:Haskell ArgumentDo Proposal by cfallin on Tuesday July 05, 2016 @02:09PM (#12038313)
I'm curious, what sorts of issues arise with complex types that Haskell-like syntax handles better? (Genuinely curious here -- I've written a little Haskell but am by no means an expert...)

IMHO a Rust-style type `Option<HashMap<String, Vec<u32>>>` is a little noiser than the Haskell-style type `Maybe (Map String [Int])`, but not fatally so. Maybe there are much worse cases though?

Re:Haskell ArgumentDo Proposal by ryani on Saturday July 09, 2016 @12:55AM (#12060161)
The big one is `->`; all the 'template argument'-inspired syntaxes for this are terrible. Once you realize you want operators (and polymorphic operators, at that!) in your types, the `<u32>`syntax falls apart.

I am not a fan of C#'s `Func<a,b>` at all.

Re:Haskell ArgumentDo Proposal by iso-8859-1 on Tuesday July 05, 2016 @04:41AM (#12035129)
Re:Haskell ArgumentDo Proposal by massysett on Monday July 04, 2016 @08:51PM (#12033804)
The problem is that ideas like this make the syntax even less readable.
Re:Haskell ArgumentDo Proposal by Peaker on Tuesday July 05, 2016 @03:27AM (#12034898)
It increases the regularity of the syntax (infix is not special) - and reduces $ noise which does not aid readability.

I have been using Haskell for around a decade and hate every infix operator spam I have to throw in there to please this syntax irregularity.

Other than this, I quite like Haskell syntax, but I remember initially hating it. It took many weeks to get used to it.