Most active commenters
  • dmead(4)
  • librasteve(3)
  • gylterud(3)

←back to thread

306 points jameshh | 25 comments | | HN request time: 1.283s | source | bottom
1. behnamoh ◴[] No.44409423[source]
Haskell has an interesting syntax: it is intuitive after someone explains it to me, but not intuitive much before the explanation.

I don't think it's because I'm used to Algol-based languages (C, Python, etc.). Every Haskell code I've seen is plagued with a plethora of operators which aim to make the code concise but it's not obvious what they do just by looking at them: https://academy.fpblock.com/haskell/tutorial/operators/

replies(4): >>44410370 #>>44410421 #>>44410532 #>>44411932 #
2. theLiminator ◴[] No.44410370[source]
> it is intuitive after someone explains it to me, but not intuitive much before the explanation

Isn't that pretty close to what something being intuitive means? Ie. something being intuitive means that it's easily understood or learned without requiring prior knowledge or instruction.

replies(1): >>44411661 #
3. the_af ◴[] No.44410421[source]
Most of the operators in that link are bog standard, and among the least interesting things to say about Haskell.

If I didn't know programming and picked at random some Java program, I wouldn't understand much either. If I didn't take a single math course and I tried to read a math formula, I wouldn't understand the operators or anything either.

The standard should be: how much can you understand once you learn the basics and do a couple of tutorials?

4. tikhonj ◴[] No.44410532[source]
At some point, I did a rough count, and the number of operators you encounter in "normal" Haskell code—avoiding lens or domain-specific libraries—was pretty close to the number of operators you'd encounter in, say, JavaScript. This was a while ago and I don't want to redo the exercise now, but, even if we're being generous to JavaScript, practical Haskell needs on the order of 2x as many operators as practical JavaScript, not 10x.

Haskell has some up-front incidental complexity, but it's a difference of degree not kind from popular starting languages. It's easy to underestimate how much you had to learn about Algol-style languages that you've just internalized so well that you don't even realize. I've taught some complete programming beginners (high or middle schoolers) Java and Python and, especially one-on-one, I've seen how they get confused by things I did not even remember required explanation!

For example, in Python, people put : in the wrong place and don't understand how = works. "Basic" syntax like : and = are far more complex than we realize, we've just learned the basics so well that it's second nature. It's similar to how native English speakers don't even realize we have rules for adjective order ("big red ball" vs "red big ball"), while language learners run into it like a brick wall.

replies(4): >>44410542 #>>44410908 #>>44412356 #>>44413399 #
5. dmead ◴[] No.44410542[source]
Combinator style, while good and well designed and all they only ended up inventing the next perl.

#haskell on freenode in the 2000s was a really fun place. I could not for the life of me convince anyone else to use the language.

replies(4): >>44410690 #>>44410730 #>>44411031 #>>44411206 #
6. eru ◴[] No.44410690{3}[source]
Combinators (in the Haskell sense) have nothing to do with whether you write your functions with letters or with comic book swearing.
7. librasteve ◴[] No.44410730{3}[source]
err, no

the perl6 guys ended up inventing the new perl (now renamed raku)

https://rakujourney.wordpress.com/2024/10/12/raku-burritos/

the first perl6 parser (pugs) was written in Haskell btw

replies(1): >>44418269 #
8. ngruhn ◴[] No.44410908[source]
I don't know if you just counted the JavaScript operators but if you count all the instances where some random symbol is used then it's really a ton. There is

    yield*
    function*
    a?.b?.c
    function f(x = 3) {
    x ??= 3
    ...
TypeScript adds even more:

    a!.b
    Type<T>
    type A = B extends C ? D : E
    ...
    
and there are countless ECMA proposals and TypeScript feature request that want to pile on even more. People seem to have zero qualms about cryptic syntax. I think the difference is that this syntax is mostly very ad-hoc. If you know the language already, this just adds a liiiittle bit extra to solve some very specific problem. On the other hand, Haskell operators like <$>, <*>, >>= are extremely general. After years I still learn about new and unexpected ways that you can use them (e.g. what the hell is `fix <$> id`). But paradoxically, because they can be used in so many seemingly unrelated contexts, you have no idea what to use them for at all initially.
9. gylterud ◴[] No.44411031{3}[source]
Oh, I owe a lot to freenode and #haskell and #math in particular. I remember one of them ran a lecture on category theory, live. It was also there I first heard about Martin-Löf type theory.

It was such a great time and place for a young person interested in learning about Haskell.

replies(1): >>44417223 #
10. tomsmeding ◴[] No.44411206{3}[source]
The IRC channel still exists! It's on libera.chat now, though.
11. gylterud ◴[] No.44411661[source]
With Haskell code it is often so that the code which actually does something is expressed in terms of combinators. These combinators are often very general, so one must do a bit of mental work to understand what they do in this particular context.

Once you understand what the combinators do in a particular context the code often reads very easily, and what it does is very intuitive and natural.

Best example I can think of is applicative parsers, where there are scattered <*> and <$> operators around, but if you just ignore them the parser just looks like a very intuitive description of what the expressions you want to parse look like.

12. mejutoco ◴[] No.44411932[source]
I think Larry Wall mentioned something like this regarding perl. Things can only be intuitive after learning them. I do not think it is syntax you are complaining about either. Some constructs in Haskell reference a certain model (monads, lenses) and no syntax is going to infuse any reader with that knowledge if they do not possess it already.
13. skybrian ◴[] No.44412356[source]
I think that’s true as far as it goes, but there are further reasons why Haskell is more difficult. Here is one:

In Haskell, the lack of parentheses for function calls plus currying means that to read a function call, you need to already know how many arguments the function takes, which I feel adds a new level of difficulty over languages where you can often guess what a function does based on its name, without looking it up.

As a result, often Haskell reads more like math, where without knowing each symbol’s definition, you’re lost.

I’ve seen cryptic JavaScript too, but less often.

replies(1): >>44412590 #
14. jameshh ◴[] No.44412590{3}[source]
> the lack of parentheses for function calls plus currying means that to read a function call, you need to already know how many arguments the function takes

While I agree with the general sentiment of what you are saying, note that the syntax has nothing to do with it, it is purely about Haskell using currying excessively. The syntactic translation between Haskell and JS is straight-forward and 1-1:

    f x y z      ->  f(x)(y)(z)
    f x (y,z) w  ->  f(x)(y,z)(w)
I agree that excessive currying is not great, and generally push for non-curried arguments unless a curried form realy is used in practice. But for this to really be comfortable, and to still enjoy all the hgiher-order programming that's nice with Haskell, we would need good records (strucural, anonymous, extensible), which it doesn't really have right now, so we are stuck with currying.
replies(1): >>44413653 #
15. IshKebab ◴[] No.44413399[source]
> practical Haskell needs on the order of 2x as many operators as practical JavaScript, not 10x.

Yeah but the JavaScript operators are almost all universally understood. There are some exceptions and mistakes, like `===` which shouldn't exist, and `.?` which is new but fairly standard. But most of the operators are just standard maths stuff, normal array/field accesses, etc.

Haskell has normal operators plus a bunch of weird operators that you need to learn. Even if the raw number of operators is only 2x, the number of operators that you have to learn is probably 10x.

Especially when you consider that Javascript operators are fixed so you have to learn them once, whereas Haskell operators are user-defined and Haskell programmers love defining them.

replies(2): >>44413635 #>>44430093 #
16. cbsmith ◴[] No.44413635{3}[source]
I still don't understand equality in JavaScript. ;-)
replies(1): >>44414488 #
17. skybrian ◴[] No.44413653{4}[source]
Yes, you could write the same thing, but defaults and language conventions matter. Writing curried functions in JavaScript is awkward enough that nobody does it by default. If you did, people would ask why in a review.
18. IshKebab ◴[] No.44414488{4}[source]
The only thing to understand is that you need a blanket ban on `==` and `!=` using ESLint.
19. dmead ◴[] No.44417223{4}[source]
Do you remember who ran it? I used to go to hack phi at UPenn, which attracted a significant chunk of the community.
replies(1): >>44419950 #
20. dmead ◴[] No.44418269{4}[source]
I'm aware. I was using the world pejoratively. Combinator style degrades into line noise.
replies(1): >>44420920 #
21. gylterud ◴[] No.44419950{5}[source]
The lecture? No, unfortunately.
22. librasteve ◴[] No.44420920{5}[source]
no doubt its fashionable to think "perl == line noise == bad"

however, there are certain sub languages (slangs) where the use of punctuation chars as operators is very helpful, of course regex is the most compelling where the code is parsing one char at a time

  my regex url {
    ^                                # Start of line
    [<http> s? '://']                # Match http or https
    ['www.' ]?                       # Optional www.
    [<[\w\-]>+ '.' ]+                # One or more domain segments
    <[a..z]> ** 2..6                 # TLD, 2 to 6 lowercase letters
    [ '/' <[\w\-./?%&=]>* ]?         # Optional path/query
    $                                # End of line
  }
imo raku has improved the situation a lot by introducing "regex 2.0" with deep support for unicode and with built in grammars that can work smoothly with regex
replies(1): >>44426795 #
23. dmead ◴[] No.44426795{6}[source]
Ahh not sure I agree. The reputation for being unreadable is pretty well deserved. It didn't happen for no reason.
replies(1): >>44427177 #
24. librasteve ◴[] No.44427177{7}[source]
ok - I agree that there was a culture of golfing and obscurity in some sections of the perl coder base

it was inevitable that a simpler language - Python - would take the big slice of scripters who wanted something easier to learn and to read

I'm sad that perl no longer has a credible niche for script level coders who want to learn a more powerful and more expressive language than Python ...

25. endgame ◴[] No.44430093{3}[source]
Haskell operators are generally well-chosen to have a consistent visual language:

* $ is "function application" - f $ x = f x, but lets you elide nested parens: f $ g $ h x = f (g (h x))

* & is "reverse function application" x & f = f x. This reads nicely in pipelines as "and"

* <$> is "fmap" what is like a lifted application over a structure: f <$> [1, 2, 3] = [f 1, f 2, f 3]

* <&> is "reverse fmap", which is nice when you have a big lambda

* Anything in <_> brackets is generally a "lifted" version of some operator

* And so on