## Right-operand currying vs Stranding

For users of dfns, both novice and expert

### 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 ← ⍤¯1`
in addition to improved readability, I no longer need ⊢ to prevent right operand and argument stranding in:
`      ⍺⍺ each ⍵`
The same would go for
`      inverse ← ⍣¯1`
and 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
`      ⍣¯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 32`
that gives the effect of two right arguments.

Phil Last

Posts: 557
Joined: Thu Jun 18, 2009 6:29 pm

### Re: Right-operand currying vs Stranding

I seem to have missed out any examples.

Consider a simple function
`      box←{'-'⍪('|',(⎕FMT ⍵),'|')⍪'-'}`
you might want to apply it a variable number of times
`      nbox←box⍣      ⍝ box n-times      1 nbox'this'------|this|------      2 nbox'this'--------|------|||this|||------|--------      3 nbox'this'----------|--------|||------|||||this|||||------|||--------|----------`
or to different ranked cells
`      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: 557
Joined: Thu Jun 18, 2009 6:29 pm

### 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.
JohnS|Dyalog

### Re: Right-operand currying vs Stranding

A few more examples of "operand currying":

Code: Select all
`InfRank    ← ⍤16            ⍝ "infinite" rankLimit      ← ⍣≡Lines      ← Cut ¯2  Tessellate ← Cut  3 Bitwise    ← ⍢((64⍴2)∘⊤)    ⍝ ⍢ is underMean       ← {(+⌿⍵)÷≢⍵}⍢`

⍟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: 215
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, ...
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: 215
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
`      succ ← +∘1      ⍝ nb: + commutative      doub ← ×∘2      ⍝ nb: × commutative`
I 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
`      first ← ⍬∘⍴      sqrt ← *∘0.5    ⍝ nb: right argument bound.`
and seeking the alternative
`      someShapeOrOtherReshapeOfThisArray ← ⍴∘thisArray      somePowerOrOtherOfThatArray ← thatArray∘*`
How could we sensibly name them? They just aren't candidates for useful functions.

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: 557
Joined: Thu Jun 18, 2009 6:29 pm

### Re: Right-operand currying vs Stranding

Exception to the last example. If thatArray is one of ¯1, 2, 4 or 16.

Phil Last

Posts: 557
Joined: Thu Jun 18, 2009 6:29 pm

Next