Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
The Hassle of Haskell (medium.com/cool-code-pal)
9 points by ayberkt on July 19, 2014 | hide | past | favorite | 6 comments


Author seems unaware that ..- might be parsed as a single operator, seems "not mathematical" to her. A good illustration how beginners in any language get hung up on small things that are different than other languages they know.


It seems like a flaw in Haskell's parser to me.

It looks like it is doing basic greedy tokenizing before passing it on to the parser, and, as this shows, that is not the best fit in this case.

Syntactically significant whitespace is seldom a good thing. (With the potential exception of indentation.)


Practically every other language does the same thing. For instance in C would you expect `int x;` to be the same as `intx;`?


No. But I expect this to not be parsed as a single comment:

     /* <stuff> */ <stuff> /* <stuff> */


I think it's just normal tokenizing. `..-` is a legal name for an operator. An error is given since no operator of that name is in scope.

The alternative of this getting parsed as a range operator and a negative number now and changing to an application of `..-` if that is ever defined or imported doesn't sound very good...


Haskell's flexibility in naming operators is unusual. Haskell allows programmers to make up their own operators. Want a spaceship operator? You can define it to be represented as <=>. Want division defined over quaternions? You can make up an operator for that too, maybe /: would be good. Working with algebraic rings? >< can be defined as the multiplicative operator over the elements of the ring.

The syntax rules for Haskell allow sequences like +++ or +.+ or <..> or <---> to all be interpreted as operators. This led to the problem for the author who may have missed the fact that Haskell was behaving in a completely consistent manner when it objected to the symbol ..- in her program. She really intended two different symbols, the .. followed by the -, but she ran them together. The error wasn't the fact that the range's end point was negative. From my perspective, the author's statement "In conclusion, I’m going to stick to Node and Rust until Haskell is further developed and at least out of beta." is over the top. I'm not claiming that I too haven't been frustrated with various programming languages and compilers and been ready (many times) to throw in the towel, who hasn't. However, I don't want readers to get the wrong idea about Haskell because of this single, and perhaps surprising, syntax error. Haskell is not in beta and is a very consistent language. I hope that the author gives Haskell another chance.

Every successful programming language has it's own characteristics and peculiarities, even at the syntactic level. PL/1 doesn't have reserved words so IF and THEN could be variables. APL has left to right operator precedence so (5 + 5 * 2) was 20 not 15. Algol-68 allows operator precedence for built in operators to be changed by the programmer! Lua arrays are indexed from 1 while C arrays are indexed from 0. Python uses whitespace to indicate code blocks. Lisp relies on parentheses. COBOL spelled out arithmetic in english words. In Forth one computes 5+(5 * 2) by writing 5 5 2 * +. So it is not at all unusual for Haskell to have it's own distinct syntax.

One of my professors told a story that I've always remembered: His very young son was walking next to him and suddenly stopped in front of a house and exclaimed "This house is broken!" His father asked "Why do you say that about this nice looking house?" His son then replied "Look at the sidewalk; there is a little crack here."




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: