I am pretty sure I saw that this exists, but I can't find it. A syntax sugar for simple functions so instead of List.map(\x -> x + 1), it's List.map(\. + 1) or something along those lines.
Nothing of that nature exists.
I think I've seen something like that in other languages though - I think Closure has a %
variable that can be used inside lambdas for this, if memory serves?
scala does this with _ https://docs.scala-lang.org/scala3/book/fun-anonymous-functions.html
oh, guess i was imagining things :sweat_smile:
Looked up to see if it was common:
Swift has $
numbers.map({ $0 * 2 })
Kotlin has it
numbers.map { it * 2 }
Ruby and Elixir have something similar too. Personally, I think Roc's regular lambda syntax looks more lightweight than regular lambdas in any of those other languages, since parentheses aren't required in the common case: List.map l \x -> x + 1
. (That's one my favorite things about Roc's syntax!) So I think a shorthand for that wouldn't be as helpful for Roc as it is for other languages.
Unlike Ajai, I get very confused when a lambda doesn't have brackets, so I always add them :sweat_smile: however, I still agree that Roc's lambda syntax is light enough that I don't find myself wanting a lighter way to write it.
That's interesting, it's always good to be reminded how subjective our syntax opinions often are. Being a native Schemer myself, you'd think I would prefer the parentheses haha
I'm not familiar with Kotlin, but that it
example immediately reminded me of javascript's this
and we can all agree this
is not good :sweat_smile:
Ah, what I was thinking of is something that does \x -> \x.foo from just .foo in addition to \x -> \x + 1, Lean allows that but uses a placeholder for the single argument of a lambda. But if it isn't already in the language, it is a good idea to not support it (it just makes things way more complicated and confusing). Especially because the lambda syntax is so light as mentioned.
Last updated: Jul 06 2025 at 12:14 UTC