Re: more flexible partial application

On 1/23/06, Sebastian Sylvan
wrote: Are there any subtle reasons for why something like the following couldn't be allowed?
foo x y z w = ... bar x w = foo x _ _ w
I.e. a more flexible version of partial application. This would be translated too
bar x w = \y z -> foo x y z w
I.e a function which takes the "_" parameters in the same order they were encountered in the function application.
I'd be against this--its semantics isn't clear enough to me. For example, I usually assume id e = e, for any e, but
id (f _ x) y = id (\y->f y x) y = f y x /= f _ x y = \z -> f z x y Or would (f _ x) y and f _ x y maybe be different? That would fix the problem above, while introducing another. Please, no! John

Or would (f _ x) y and f _ x y maybe be different? That would fix the problem above, while introducing another. Please, no!
seconded. I think the original problem (want to omit lambda notation in a few cases) does not need to be fixed. Functions with too many parameters are bad style anyway, in most cases there should actually be a record type for them. See Code Smell: long parameter list, Refactoring: introduce parameter object. e. g. http://wiki.java.net/bin/view/People/SmellsToRefactorings On the other hand, standard OO languages do not have partial evaluation so perhaps this changes the idea a bit. The question is, how much. best regards, -- -- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 -- ---- http://www.imn.htwk-leipzig.de/~waldmann/ -------

On 1/26/06, John Hughes
I'd be against this--its semantics isn't clear enough to me. For example, I usually assume id e = e, for any e, but
id (f _ x) y = id (\y->f y x) y = f y x /= f _ x y = \z -> f z x y
Or would (f _ x) y and f _ x y maybe be different? That would fix the problem above, while introducing another. Please, no!
They should be different for this to work. The reasonable thing to do would be to rewrite every (e _ a1 a2 ... an) as (\x -> (e x a1 a2 ... an)) and the parentheses should be mandatory. Note that this can be done recursively, so that e.g. (f _ y _ t) ==> (\x1 -> (f x1 y _ t)) ==> (\x1 -> (\x2 -> (f x1 y x2 t))) I see this as no worse than operator sections: we already have (- x) and (-) x meaning different things. Having in mind that (e _ ...) is just syntax, it should be easy to keep it separate from application, so f x y z will still be the same as ((f x) y) z.
John
Cheers, Dinko

Hi folks John Hughes wrote:
On 1/23/06, Sebastian Sylvan
wrote: Are there any subtle reasons for why something like the following couldn't be allowed?
foo x y z w = ... bar x w = foo x _ _ w
Or would (f _ x) y and f _ x y maybe be different? That would fix the problem above, while introducing another. Please, no!
For what it's worth, I agree with John. In my wild and foolish youth (c1990), I implemented a programming language with this very feature. It was a kind of higher-order LOGO on the complex plane, where a function applied to a drawing transformed its coordinates. We'd do daft stuff like (200 * _ ^ 2) unitsquare What fun we had, but it was a source of top quality mystery as far as the semantics was concerned. Figuring out how to bracket stuff was total guesswork. As things stand in Haskell, parentheses do grouping, and they do sections for infix operators. These are cleanly separable, because what's in a section bracket is plainly not an expression. Extra explicit grouping of expressions is harmless. (f a) b is f a b. Giving parentheses this murky binding power interferes with their innocence. If you do want to pull a stunt like this, you need some other funny brackets which specifically indicate this binding power, and then you can do grouping inside them, to create larger linear abstractions. You could have something like (| f (_ * 3) _ |) This makes some kind of sense, provided you don't expect to be able to transform the contents of these brackets naively (| flip f _ _ |) ain't (| f _ _ |) But in my wild and foolish adulthood, I'm not sure it's worth spending a kind of bracket on. All the best Conor

On 1/26/06, Conor McBride
We'd do daft stuff like
(200 * _ ^ 2) unitsquare
Yes, I played with a concept like that at one point, and came to the conclusion that it was better done with lambdas. I am all specifically about function application, not arbitrary expressions. [...]
Giving parentheses this murky binding power interferes with their innocence.
The parentheses won't bind, they'll only delimit the expression that will be subject to re-interpretation, and then simply in a by-the-way manner, very much like in the operator sections case. They'll still be innocent in the absense of relevant syntax :)
If you do want to pull a stunt like this, you need some other funny brackets which specifically indicate this binding power, and then you can do grouping inside them, to create larger linear abstractions. You could have something like
(| f (_ * 3) _ |)
We already have lambdas for this, and they're shorter, clearer, and more powerful.
But in my wild and foolish adulthood, I'm not sure it's worth spending a kind of bracket on.
Definitely not. But an underscore can still be spent on the much simpler case :)
All the best
Conor
Cheers, Dinko

On 2006-01-26, Dinko Tenev
On 1/26/06, Conor McBride
wrote: [...] We'd do daft stuff like
(200 * _ ^ 2) unitsquare
Yes, I played with a concept like that at one point, and came to the conclusion that it was better done with lambdas. I am all specifically about function application, not arbitrary expressions.
Arbitrary expressions are just function application.
If you do want to pull a stunt like this, you need some other funny brackets which specifically indicate this binding power, and then you can do grouping inside them, to create larger linear abstractions. You could have something like
(| f (_ * 3) _ |)
We already have lambdas for this, and they're shorter, clearer, and more powerful.
The same hold (except for shorter) for this whole extension, and I don't know that "shorter" holds here. -- Aaron Denney -><-

On 1/26/06, Aaron Denney
On 2006-01-26, Dinko Tenev
wrote: On 1/26/06, Conor McBride
wrote: [...] We'd do daft stuff like
(200 * _ ^ 2) unitsquare
Yes, I played with a concept like that at one point, and came to the conclusion that it was better done with lambdas. I am all specifically about function application, not arbitrary expressions.
Arbitrary expressions are just function application.
...arbitrarily deeply nested. I meant looking at a single level of function application, with all the consequences for how high up the tree the underscore may "escape" as a lambda. You're probably going to tell me that f x y z represents 3 different levels, but many folks would see this as little more than a cute way of writing f(x, y, z), and they'll have a point, given how the concept of "partial" application is bandied every so often. It is quite reasonable to identify a minimal enclosing application, with all visible arguments consumed up to the innermost enclosing pair of parentheses. Sure, it's not a very elegant concept, but neither is the current mechanism for operator sections (which does exactly the same.) The only implication will be that you won't be able to use sections *and* emphasize the order of application at the same time, and I am yet to hear from anyone who prefer (((f x) y) z) to (f x y z) in their code. BTW, it just occurred to me that if this section syntax is extended to operators as well, it would cure the rather embarrassing case of the "-" operator :)
If you do want to pull a stunt like this, you need some other funny brackets which specifically indicate this binding power, and then you can do grouping inside them, to create larger linear abstractions. You could have something like
(| f (_ * 3) _ |)
We already have lambdas for this, and they're shorter, clearer, and more powerful.
The same hold (except for shorter) for this whole extension, and I don't know that "shorter" holds here.
I missed an underscore, so you have your point about "shorter." About the whole extension, (f x _ z) is arguably clearer than \y -> f x y z, and is also really unobtrusive syntactic sugar, very much unlike a new kind of brackets.
-- Aaron Denney -><-
Cheers, Dinko

Am Freitag, 27. Januar 2006 12:15 schrieb Dinko Tenev:
[...]
About the whole extension, (f x _ z) is arguably clearer than \y -> f x y z,
For me, it's really not clearer. (f x _ z) looks like an application of f to three arguments since _ looks like a special expression (similar to _ in patterns being a special pattern).
[...]
Best wishes, Wolfgang

On 1/27/06, Wolfgang Jeltsch
Am Freitag, 27. Januar 2006 12:15 schrieb Dinko Tenev:
[...]
About the whole extension, (f x _ z) is arguably clearer than \y -> f x y z,
For me, it's really not clearer. (f x _ z) looks like an application of f to three arguments since _ looks like a special expression (similar to _ in patterns being a special pattern).
I feel tempted to argue to the contrary, but at this point of the argument, I think it's already a matter of personal preference. Cheers, Dinko
participants (6)
-
Aaron Denney
-
Conor McBride
-
Dinko Tenev
-
Johannes Waldmann
-
John Hughes
-
Wolfgang Jeltsch