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

Roc is a similar functional language that doesn't automatically curry functions and doesn't have partial application, the Roc FAQ has a few reasons: https://www.roc-lang.org/faq.html#curried-functions


EDIT: quick note, this is a tangent; Gleam does support partial application with `_` and it works with pipelines as well.

> This is not how it works in curried languages, however. In curried languages with a |> operator, the first expression still returns "Hello, World!" but the second one returns "World!Hello, " instead. This can be an unpleasant surprise for beginners, but even experienced users commonly find that this behavior is less useful than having both of these expressions evaluate to the same thing.

The upside (on the curried side) is that you can define `|>` as a normal function (even without lazy semantics, as in OCaml.) How much of an "upside" this is will vary, but note that this generalizes to many other operators that can be added. The rest is a matter of API design, i.e., the order of arguments and the use of named arguments (and/or other syntax sugar.) For example, in the case of the post's example:

    "Hello, "
    |> Str.concat "World!"
You can get the "beginner friendly" semantics with just a little change to the `Str.concat` (assuming named args support, using OCaml syntax):

    "Hello, "
    |> Str.concat ~rest:["World!"]

In non-curried languages, this has to be a macro (or it needs to be built-in). If you already have macros in your language - that's good: you can easily make `|>` do things like `x |> func(arg1, _, arg2)` and more. However, if you make this a special case in the language, it will be hard to extend and impossible to generalize. So personally, I'd grade the options in order of power and convenience:

    - infix macros
    - infix functions in curried languages
    - special, hardcoded |> operator
    - beating your language black and blue until you get a work-alike (like with implicits in Scala)
There's also a special category of languages where pipelines are primitives (shells, jq), but that is outside the scope of this comment, since they are more than syntactic sugar for function application :)


I don't even think curried functions by default is a good idea, but that article really made me support them. Richard Feldman is usually so reasonable, what happened? That's the worst argument I've seen in a while.




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

Search: