Get rid of auto-currying, add syntax for currying/partial app. #1071
Replies: 1 comment
-
My personal preference would be to keep auto-currying. However, I think a syntax for the abbreviated definition of anonymous functions would be valuable regardless, and I do recognize there is merit to having an alternate syntax for partial application as it would communicate more information to readers of the code. Below are some related ideas from other languages. In particular, Racket's curly-fn library essentially combines Idea1 and Idea2. SRFI 26https://srfi.schemers.org/srfi-26/srfi-26.html (cut f x <>) (fn (y) (f x y) or for right partial appliction (cut f <> x) (fn (y) (f y x)) Note for a ternary function (cut h x <> <>) would be equivalent to (fn (y z) (h x y z)) and would have the type (cut g (f x <>) <>) would be equivalent to (fn (y) (g (f x <>) y) and would likely fail to compile because The (cut g (cut f x <>) <>) would be the partial application of g to the partial application of (fn (z)
(fn (y)
(g (f x y) z))) Finally Clojure's Anonymous function syntaxhttps://clojure.org/guides/learn/functions#_anonymous_function_syntax The partial application of #(f x %) and swapping the argument in #(f %2 %1) Unlike #(g (f %) ) %) would be equivalent to (fn (x) (g (fn (y) (f x y)) x) Clojure does not allow nesting of abbreviated function definitions: #(g #(f x %) %)
is a syntax error. This limitation means it cannot replace Rackethttps://github.com/lexi-lambda/racket-curly-fn The partial application of #{f x %} and swapping the arguments would be #{f %2 %1} It also supports the curried version like Idea 1, which Clojure's This is essentially the same as Idea1 and Idea2 combined, with Mathematicahttps://www.wolfram.com/language/elementary-introduction/2nd-ed/26-pure-anonymous-functions.html F[x, #]& is the partial application of F[#2, #1]& |
Beta Was this translation helpful? Give feedback.
-
"Auto-currying" is a very cool feature for some very slick and compact code. I love being able to write
(* 2)
as a doubling function, for example.However, I find that in general, auto-currying is more trouble than the entry fee it paid:
As such, I'd propose we break an ML/Haskell tradition and get rid of it as a default, and instead use another syntax. Some ideas follow. In the following ideas, the spirit is what I'm aiming for, i.e., whether it's
_
or$
or something else is open to discussion.Idea #1: Curry syntax
Suppose
f : t -> t -> t
. The syntax[f x]
would represent the curried functiont -> t
.Idea #2: Same as #1, but with partial application
Suppose the same
f
. Then the above could be written[f x _]
. The other argument could be[f _ x]
. Multiple arguments could bef == [f _1 _2]
andflip f == [f _2 _1]
.Beta Was this translation helpful? Give feedback.
All reactions