[Haskell-beginners] Feature request: anonymous arguments

Karl Voelker karl at karlv.net
Sat Aug 30 08:31:09 UTC 2014


On Sat, Aug 30, 2014, at 12:21 AM, Julius Gedvilas wrote:

Anonymous argument (AA) is an argument without a name.

w/o AA:
func :: a -> a -> a -> a
func aa0 aa1 aa2 = aa0 `op` aa1 `op` aa2
\aa0 aa1 aa2 -> aa0 `op` aa1 `op` aa2

w/ AA:
func :: a -> a -> a -> a
func = \0 `op` \1 `op` \2
\-> \0 `op` \1 `op` \2



I think you have identified a real problem - sometimes, our
functions are so abstract that it is difficult to name the
parameters.



That said, I can think of a few cons to your proposal:



1. With lexically nested functions, you lose the ability to
refer to arguments of the outer function inside the inner
function if both functions use AA.



2. If you add a new parameter to a function anywhere other than
at the end, the effective "names" of all the following
parameters change. This is especially dangerous if many of the
parameters have the same types, since you could easily fail to
update some of the references to those arguments, and your
function would still



3. Reusing the backslash is not so simple. For example, "\0 ->
1" is a syntactically valid function in Haskell already.



4. It's not really any shorter than the alternative, which is
to just use very short variable names.



-Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140830/40e8e2b4/attachment.html>


More information about the Beginners mailing list