Right-operand currying vs Stranding
15 posts
• Page 1 of 2 • 1, 2
Right-operand currying vs Stranding
FYI: I've been playing with a data structure in which I choose to represent a shape-v array of things as a shape (2,v) array of numbers. I find I wind up using:
⍺⍺⍤¯1 ⊢⍵a fair amount to apply some function ⍺⍺ to each thing in array-of-things ⍵. I discovered that If I set:
each ← ⍤¯1in addition to improved readability, I no longer need ⊢ to prevent right operand and argument stranding in:
⍺⍺ each ⍵The same would go for
inverse ← ⍣¯1and any other dyadic operator, primitive or defined, with an array right operand.
- JohnS|Dyalog
Re: Right-operand currying vs Stranding
Power and Rank with negative-one right operand
Unfortunately right at this moment I can't think of any others.
Are you also considering left operand currying of conjunctions?
This topic relates to a recent thread in comp.lang.apl where the arguments of residue are under discussion. Aaron Hsu refers to the auxiliary and substantive arguments which in APL are often left and right. He argues that this permits the monadic form of a primitive to be directly related to the dyad with its auxiliary argument edilded.
From both Rank and Power we see that the roles are often reversed for conjunctions, the substantive operand being on the left - the auxiliary on the right.
Currying the right operand can then be seen as effectively eliding the left or substantive. More generally useful would be the ability to curry the substantive leaving the auxiliary to be the only missing link in forming an entire family of related functions.
This of course means that in order to call the derived adverb the auxiliary is now placed on the left, giving the effect of two left operands. An oddity with a ready precedent, albeit reversed, in the derivation function-compose-array, e.g. decrement
⍣¯1 ⋄ ⍤¯1- Inverse and major-cell - are special cases that certainly deserve a mention and the ability to become first-class objects.
Unfortunately right at this moment I can't think of any others.
Are you also considering left operand currying of conjunctions?
This topic relates to a recent thread in comp.lang.apl where the arguments of residue are under discussion. Aaron Hsu refers to the auxiliary and substantive arguments which in APL are often left and right. He argues that this permits the monadic form of a primitive to be directly related to the dyad with its auxiliary argument edilded.
From both Rank and Power we see that the roles are often reversed for conjunctions, the substantive operand being on the left - the auxiliary on the right.
Currying the right operand can then be seen as effectively eliding the left or substantive. More generally useful would be the ability to curry the substantive leaving the auxiliary to be the only missing link in forming an entire family of related functions.
This of course means that in order to call the derived adverb the auxiliary is now placed on the left, giving the effect of two left operands. An oddity with a ready precedent, albeit reversed, in the derivation function-compose-array, e.g. decrement
dec←-∘1 ⋄ dec 3that gives the effect of two right arguments.
2
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Right-operand currying vs Stranding
I seem to have missed out any examples.
Consider a simple function
Consider a simple function
box←{'-'⍪('|',(⎕FMT ⍵),'|')⍪'-'}you might want to apply it a variable number of times
nbox←box⍣ ⍝ box n-timesor to different ranked cells
1 nbox'this'
------
|this|
------
2 nbox'this'
--------
|------|
||this||
|------|
--------
3 nbox'this'
----------
|--------|
||------||
|||this|||
||------||
|--------|
----------
rbox←box⍤ ⍝ box r-cells
1 rbox ⍳2 2 2
----------------
| 0 0 0 0 0 1 |
----------------
----------------
| 0 1 0 0 1 1 |
----------------
----------------
| 1 0 0 1 0 1 |
----------------
----------------
| 1 1 0 1 1 1 |
----------------
2 rbox ⍳2 2 2
----------------
| 0 0 0 0 0 1 |
| 0 1 0 0 1 1 |
----------------
----------------
| 1 0 0 1 0 1 |
| 1 1 0 1 1 1 |
----------------
3 rbox ⍳2 2 2
----------------
| 0 0 0 0 0 1 |
| 0 1 0 0 1 1 |
| |
| 1 0 0 1 0 1 |
| 1 1 0 1 1 1 |
----------------
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Right-operand currying vs Stranding
Hi Phil, These are persuasive arguments. We did have a research project to implement "Monadic Operator Expressions" (MOXs), which would have provided left operand currying, but it didn't make it to the release. All I can promise is to raise your suggestions as a topic when devt is blue-skying - but I can't guarantee anything.
John.
John.
- JohnS|Dyalog
Re: Right-operand currying vs Stranding
A few more examples of "operand currying":
⍟Mean is geometric mean; ÷Mean harmonic mean; *∘2 Mean root mean square; and of course ⊢Mean is the ordinary arithmetic mean.
The variant operator ⍠ should be a fruitful source of useful instances of fixing the right operand.
Many APL primitive dyadic functions were designed so that fixing the left argument makes a sensible monadic function, and it does appear that APL primitive dyadic operators were designed so that fixing the right operand makes a sensible monadic operator.
- Code: Select all
InfRank ← ⍤16 ⍝ "infinite" rank
Limit ← ⍣≡
Lines ← Cut ¯2
Tessellate ← Cut 3
Bitwise ← ⍢((64⍴2)∘⊤) ⍝ ⍢ is under
Mean ← {(+⌿⍵)÷≢⍵}⍢
⍟Mean is geometric mean; ÷Mean harmonic mean; *∘2 Mean root mean square; and of course ⊢Mean is the ordinary arithmetic mean.
The variant operator ⍠ should be a fruitful source of useful instances of fixing the right operand.
Many APL primitive dyadic functions were designed so that fixing the left argument makes a sensible monadic function, and it does appear that APL primitive dyadic operators were designed so that fixing the right operand makes a sensible monadic operator.
- Roger|Dyalog
- Posts: 238
- Joined: Thu Jul 28, 2011 10:53 am
Re: Right-operand currying vs Stranding
Nice examples. The first five, which use right-operand currying, are uncontentious and would just work if the operators (Cut and Under) were available. Left-operand currying, such as Roger's last example "Mean", is more problematic.
Many treatments of APL (see http://dfns.dyalog.com/n_parse.htm) parse dyadic functions and operators by first binding left argument and right operand, respectively, to form a monadic function or operator. This intermediate binding is sometimes available to the programmer (inv←⍣≡) and sometimes not (succ←1+) but could be. Dyalog certainly takes this approach with dyadic operators. It could be amended to allow left-operand currying but this is not quite so straightforward to implement given the current parser.
I like Aaron's description of the left argument as auxiliary. Viewed this way, left arguments could be seen as qualifiers and feel a bit like noun adjuncts in English: college student, shop window, two residue, bicycle thief, three reshape, fashion victim, ten logarithm, noun adjunct, one rotation, cube root, toffee pudding, ...
Many treatments of APL (see http://dfns.dyalog.com/n_parse.htm) parse dyadic functions and operators by first binding left argument and right operand, respectively, to form a monadic function or operator. This intermediate binding is sometimes available to the programmer (inv←⍣≡) and sometimes not (succ←1+) but could be. Dyalog certainly takes this approach with dyadic operators. It could be amended to allow left-operand currying but this is not quite so straightforward to implement given the current parser.
I like Aaron's description of the left argument as auxiliary. Viewed this way, left arguments could be seen as qualifiers and feel a bit like noun adjuncts in English: college student, shop window, two residue, bicycle thief, three reshape, fashion victim, ten logarithm, noun adjunct, one rotation, cube root, toffee pudding, ...
- JohnS|Dyalog
Re: Right-operand currying vs Stranding
I have a hard time thinking of either argument of - ÷ * ⍟ ... as “auxiliary” or “substantive”, of one argument being more important than the other.
- Roger|Dyalog
- Posts: 238
- Joined: Thu Jul 28, 2011 10:53 am
Re: Right-operand currying vs Stranding
Fair point. Perhaps I'm confusing asymmetry of arguments (auxiliary vs substantive) with the opportunity to bind one of them (as a "parameter"?) to form a useful monadic function:
succ ← 1∘+ ⍝ nb: + commutative
doub ← 2∘× ⍝ nb: × commutative
odd ← 2∘|
sin ← 1∘○
first ← ⍬∘⍴
sqrt ← *∘0.5 ⍝ nb: right argument bound.
etc
- JohnS|Dyalog
Re: Right-operand currying vs Stranding
All John's examples derive monads requiring a single argument. Discounting the first two which could equally be
If the concept is at all useful I should want to definee the substantive argument of a dyad, if there is one, to be the one that cannot reasonably or usefully be bound.
succ ← +∘1 ⍝ nb: + commutativeI should argue that in every other case the missing argument, whether left or right, would be the substantive of the dyad. Taking the last two only because I don't want to bore you
doub ← ×∘2 ⍝ nb: × commutative
first ← ⍬∘⍴and seeking the alternative
sqrt ← *∘0.5 ⍝ nb: right argument bound.
someShapeOrOtherReshapeOfThisArray ← ⍴∘thisArrayHow could we sensibly name them? They just aren't candidates for useful functions.
somePowerOrOtherOfThatArray ← thatArray∘*
If the concept is at all useful I should want to definee the substantive argument of a dyad, if there is one, to be the one that cannot reasonably or usefully be bound.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Right-operand currying vs Stranding
Exception to the last example. If thatArray is one of ¯1, 2, 4 or 16.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
15 posts
• Page 1 of 2 • 1, 2
Return to Functional Programming
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group