Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The $ operator is nothing but syntactic sugar that allows you to write bar $ foo data instead of having to write bar (foo data). That’s it.

Actually, it's even simpler than that: the $ operator is nothing but a function that applies its left argument to its right one! The full definition is

    f $ x = f x
(plus a directive that sets its precedence and association)


This kind of thing is emblematic of how little Haskellers care about readability and discoverability. I'm sure it's great for people that are already expert Haskellers but it adds yet another thing to learn (that's really hard to search for!) and the benefit is... you can skip a couple of brackets. Awesome.


Skipping brackets is incredibly useful for readability. Basically every language that relies on brackets has settled on a style convention that makes the redundant with indentation. Admittedly, the big exception to this is function application. But Haskell is much more function oriented, so requiring brackets on function application is much more burdensome than in most languages.

As to searchability, this should be covered in whatever learn Haskell material you are using. And if it isn't, then you can literally just search for it in the Haskell search engine [0].

[0] https://hoogle.haskell.org/?hoogle=%24&scope=set%3Astackage


I agree with this sentiment. The one thing I liked about Clojure was the simplicity of the syntax, as long as you kept away from writing macros.

In general, after so many decades programming, I've come to dislike languages with optional periods (a.foo) and optional parenthesis for function calls - little gain to a confusion of precedence, what's a field vs method. Seems that the whole DSL craze of 15 years ago was a mistake after all.

Having said all that, I think haskell is awesome, in the original sense of the word. I became a better programmer after working with it for a bit.


Haskell has it's issues, but this really ain't it. $ is idiomatic and used all over the place and is greatly more readable than stacking up brackets. The discoverability is also great because, like most things in Haskell, you can literally just input it into hoogle: https://hoogle.haskell.org/?hoogle=%24 and the first hit is, of course the definition of it. Which includes a full explanation what it does.


Excessive brackets are an evergreen complaint against lisp.

Here's one that made the front page, same time as your comment: https://news.ycombinator.com/item?id=43753381


You can type `:doc $` in ghci and it will tell you how the function is defined and give you usage examples.


We aren’t enthusiastic about having to do that either


Why? It’s the official documentation. Most haskellers have gchi open at all times when coding.


Because (as far as I know) that's not the case for most other languages. It's an interesting (and certainly not necessarily "wrong") way to program when you aren't sure about how to write something. Python has something similar, that I will occasionally utilize for this purpose, but it doesn't show documentation (as far as I know) or anything like that while it sounds like gchi has functionality kind of like CLI tools' "--help"?

With C#, intellisense takes the role of gchi and does pop up say the valid methods and properties of a class, and iirc includes documentation text.

So it's less about that haskell has "coding help" built in and more about how that's presented to and interacted by the developer.


Python does indeed have similar functionality:

    $ py
    >>> help(print)

    $ ghci
    λ> :doc $
This returns the same documentation provided by intellisense.


Right on.

To be clear, the core "issue" is whether developers use or like to use that functionality, and to that end I say I never use it for Python (obviously- since I didn't know of its existence). More succinctly, it seems like other languages have "more popular" alternatives.


Agreed! I've never found myself making much use of Python's help feature, but I do all the time in Haskell! Wonder why?


If you're being facetious, I would love to know why you use Haskell's but not Python's. Is it a better UX? A lack of alternatives like intellisense?


Totally serious. I'm not claiming it's the best, but it's how I use the tools. There's a few reasons:

1. It's just how I learned. Googled my way through Python, then learned Haskell much later via a book which explicitly recommends using the REPL to get info about functions.

2. Types. I'm typically only looking for type information. A quick `:t` or `:i` is usually all I need in Haskell. I know Python half has them now, but I'm not

3. I'm certainly weird here, but I turn autocomplete and other pop-ups off. I find it distracting, and prefer the more intentional action of typing stuff into a REPL. Heck, I even do it in the VSCode terminal.

In summary: IDK, weird I guess. I should probably use it more in Python.


You're only new once, but you write lines that benefit from $ every day.


That argument values learnability and discoverability at 0.


What do you mean by discoverability? What is the bar? Like is `:=` not discoverable in python. Or are ternaries not discoverable in Javascript? I'd say these are equally mysterious to a new learner. Just because $ is unfamiliar, doesn't mean it's worse than any other language construct.

Also, literally the first hit when you google “what does $ do in Haskell” is an explanation. So it’s in the docs, easily googlable, and one of the first things all learning material explains. How is that not discoverable?


No, it really doesn't. It values language ergonomics higher than learnability. That doesn't mean learnability is valued at 0. It has nothing to do with discoverability.


In Haskell, ($) = `id`, because "id f x" = "(id f) x" = "f x".




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: