Feature request: anonymous arguments

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 AA syntax: '\n', where n is one of the (0 1 2 3 4 5 6 7 8 9). 'n' corresponds to the position of a parameter. I think a language shouldn't force you to invent names for things that are used only once, same philosophy as with an anonymous function. Is this feature needed? Does something like this already exist?

Often this is sidestepped by using partial application since most functions
are curried, although, I can still see this being useful.
Ex.
f a b c = a + b - c
g = ((-) .) . (+)
Clearly this isn't as intuitive a definition, but it does remove the
argument names.
I can't help but think that there must be some gnarly lens that solves
this, but I can't think of one :)
On Sat, Aug 30, 2014 at 5:21 PM, Julius Gedvilas
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
AA syntax: '\n', where n is one of the (0 1 2 3 4 5 6 7 8 9). 'n' corresponds to the position of a parameter.
I think a language shouldn't force you to invent names for things that are used only once, same philosophy as with an anonymous function.
Is this feature needed? Does something like this already exist?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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

0. And more specific functions hopefully has more specific types, which
even more reduce a need for an extra name in a namespace.
1. I do not suggest to replace named arguments entirely. Anonymous
functions more so does not replace their named counterparts, but find their
place in a language (... in the logo (\);).
2. Adding parameters is a sub-process of a larger refactoring rather then
an "edit on the fly", or so do I think ...
3. Is it? *GHCi *does not recognize it.
4. It is shorter, but most important it does reduce number of useless
things (like one letter arg names), for benefit of both writer and reader
(and compiler).
On Sat, Aug 30, 2014 at 11:31 AM, Karl Voelker
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
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Sat, Aug 30, 2014, at 02:32 AM, Julius Gedvilas wrote: 3. Is it? GHCi does not recognize it. Prelude> :t \0 -> 1 \0 -> 1 :: (Num a1, Num a, Eq a) => a -> a1

... my bad
On Sat, Aug 30, 2014 at 12:58 PM, Karl Voelker
On Sat, Aug 30, 2014, at 02:32 AM, Julius Gedvilas wrote:
3. Is it? *GHCi *does not recognize it.
Prelude> :t \0 -> 1 \0 -> 1 :: (Num a1, Num a, Eq a) => a -> a1
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

\0 -> 1 :: (Num a1, Num a, Eq a) => a -> a1
Actually this is fairly interesting. I need to dig into it.
On Sat, Aug 30, 2014 at 12:59 PM, Julius Gedvilas
... my bad
On Sat, Aug 30, 2014 at 12:58 PM, Karl Voelker
wrote: On Sat, Aug 30, 2014, at 02:32 AM, Julius Gedvilas wrote:
3. Is it? *GHCi *does not recognize it.
Prelude> :t \0 -> 1 \0 -> 1 :: (Num a1, Num a, Eq a) => a -> a1
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

It is pattern recognition of the case for which the argument is zero. The
function will return 1 if provided with 0, but will throw a non-exhaustive
patterns in lambda exception for any other correctly typed input.
On Aug 30, 2014 1:06 PM, "Julius Gedvilas"
\0 -> 1 :: (Num a1, Num a, Eq a) => a -> a1
Actually this is fairly interesting. I need to dig into it.
On Sat, Aug 30, 2014 at 12:59 PM, Julius Gedvilas
wrote: ... my bad
On Sat, Aug 30, 2014 at 12:58 PM, Karl Voelker
wrote: On Sat, Aug 30, 2014, at 02:32 AM, Julius Gedvilas wrote:
3. Is it? *GHCi *does not recognize it.
Prelude> :t \0 -> 1 \0 -> 1 :: (Num a1, Num a, Eq a) => a -> a1
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (4)
-
Julius Gedvilas
-
Karl Voelker
-
Lyndon Maydwell
-
Yuval Langer