Most active commenters

    ←back to thread

    611 points LorenDB | 14 comments | | HN request time: 0.001s | source | bottom
    Show context
    choeger ◴[] No.43912866[source]
    All this has been known in the PL design community for decades if not half a century by now.

    Two things are incredibly frustrating when it comes to safety in software engineering:

    1. The arrogance that "practitioners" have against "theorists" (everyone with a PhD in programming languages)

    2. The slowness of the adoption of well-tested and thoroughly researched language concepts (think of Haskell type classes, aka, Rust traits)

    I like that Rust can pick good concepts and design coherent language from them without inventing its own "pragmatic" solution that breaks horribly in some use cases that some "practitioners" deem "too theoretical."

    replies(4): >>43913128 #>>43915349 #>>43916215 #>>43917609 #
    Ygg2 ◴[] No.43913128[source]
    > I like that Rust can pick good concepts and design coherent language from them without inventing its own "pragmatic" solution that breaks horribly in some use cases that some "practitioners" deem "too theoretical."

    I've thought Rust picked some pretty nifty middle ground. On one side, it's not mindfucking unsafe like C. It picked to remove a set of problems like memory safety. On the other side, Rust didn't go for the highest of theoretical grounds. It's not guaranteeing much outside of it, and it also relies a bit on human help (unsafe blocks).

    replies(1): >>43913258 #
    eptcyka ◴[] No.43913258[source]
    As per the article, Rust has benefits beyond the ones afforded by the borrow checker.
    replies(1): >>43913710 #
    Ygg2 ◴[] No.43913710[source]
    Sure, but it is pragmatic in other ways as well :)

    It takes ADT, but not function currying, and so on.

    replies(2): >>43913760 #>>43913876 #
    1. andrepd ◴[] No.43913876[source]
    I don't think currying is that big a deal, it's just syntactic sugar that might or might not make things easier to read, unlike ADTs or closures which are important core concepts.

    I'd love to have a syntax like

        { foo(%1, bar) }
    
    standing for

        |x| { foo(x, bar) }
    
    though. I'm not aware of any language that has this!
    replies(10): >>43914073 #>>43914288 #>>43914655 #>>43914762 #>>43914803 #>>43915598 #>>43916123 #>>43920249 #>>43922459 #>>43925563 #
    2. Munksgaard ◴[] No.43914073[source]
    Elixir has this, which is close:

        &foo(&1, bar)
    3. tcfhgj ◴[] No.43914288[source]
    Powershell has this, why do you like this?
    4. masijo ◴[] No.43914655[source]
    Clojure has this

        user=> (#(println %1 %2) "Hello " "Clojure")
        Hello Clojure
    5. tormeh ◴[] No.43914762[source]
    I'd argue that currying is actively harmful (I suspect you agree). I've seen functions take one argument in one source file, and the next argument in another source file. In JavaScript no less. Horrendous stuff. One of my most hated anti-features, along with Scala's implicits. These kinds of features are mostly misused rather than used.
    replies(1): >>43917127 #
    6. tmoertel ◴[] No.43914803[source]
    Mathematica has this:

        In[1]:  Map((1 + #1)&, {a, b, c})
        Out[1]: {a + 1, b + 1, c + 1}
    
    See https://reference.wolfram.com/language/ref/Function.html.en for the full story.
    replies(1): >>43922222 #
    7. GrantMoyer ◴[] No.43915598[source]
    C++ has this[1], kind of, but please don't actually use it.

    > for_each(a.begin(), a.end(), std::cout << _1 << ' ');

    Also, Scala has something similar as a first class feature[2].

    [1]: https://www.boost.org/doc/libs/1_88_0/doc/html/lambda.html

    [2]: https://scala-lang.org/files/archive/spec/3.4/06-expressions...

    8. icen ◴[] No.43916123[source]
    In K the arguments are named x y z by default, so you just write:

        { foo[x, bar] }
    9. bunderbunder ◴[] No.43917127[source]
    From what I've seen, partial application tends to be used for utmost good in dialects of ML, and utmost evil most everywhere else. Chaotic neutral in R/tidyverse.
    10. cobbal ◴[] No.43920249[source]
    swift has this as well

        { foo($0, bar) }
    11. zelphirkalt ◴[] No.43922222[source]
    What is that & doing there? I thought it looks neat, but then that & ...
    replies(1): >>43941722 #
    12. int_19h ◴[] No.43922459[source]
    As noted in other comments, a bunch of languages has it, but the problem with this syntax is that it doesn't generalize well. For example, let's say we have:

       foo(%1, bar(%1, 42)) 
    
    does this desugar to:

       |x| foo(x, |y| bar(y, 42)) 
    
    or to:

       |x| foo(x, bar(x, 42)) 
    
    and do you trust the person reading this code later to remember which one it is?
    13. _flux ◴[] No.43925563[source]
    I think currying is an important concept and not sugar at all, as it means each function takes exactly one parameter, i.e. in OCaml foo bar baz is equal to (foo bar) baz. Of course, some other languages can try to emulate the use of currying and the original original idea no longer exists there.

    I'm relatively sure there exists such a language you are looking for, but I've forgotten its name :(.

    There was a syntax extension pa_holes for OCaml (which you perhaps know, as it is natively currying) that worked like

        (\ foo \1 bar)
    
    and it would become

        fun x -> foo x bar
    
    I'm sure the extension was inspired by some other language.. And the pa syntax extension extension mechanism for OCaml has been replaced by ppx a long time ago already; maybe the new system doesn't enable such succinct extensions.
    14. tmoertel ◴[] No.43941722{3}[source]
    The & is a postfix operator that converts an expression into an anonymous function. See “Pure Functions”:

    https://reference.wolfram.com/language/tutorial/FunctionalOp...