Re: Justification for the "reversed" instruction format

2016-09-08 Thread Trey Harris
On Thu, Sep 8, 2016 at 9:23 AM Aaron Sherman a...@ajs.com
 wrote:

I don't know Haskell, but isn't flip just:
>
> sub flip() { -> $b, $a, |c { f($a, $b, |c) } }
>
> And then:
>
> perl6 -e 'sub flip() { -> $a, $b, |c { f($b, $a, |c) } }; my  = flip
>  yas(1,2,3)'
> 213
>
> Yes—but my worry about that was that it wouldn’t carry over signature
constraints and coercions as a specific argument-flipper sub written with
the same signature (flipped). Haskell does deep type inference, unlike Perl
6, so simply writing flip f x y = f y x is sufficient to get exactly the
same behavior in constrained or coercive contexts.


> Aaron Sherman, M.:
> P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
> Toolsmith, developer, gamer and life-long student.
>
>
> On Wed, Sep 7, 2016 at 6:13 PM, Brandon Allbery 
> wrote:
>
>> On Wed, Sep 7, 2016 at 6:08 PM, Parrot Raiser <1parr...@gmail.com> wrote:
>>
>>> There is a "flip" in P6, to reverse the characters in a string, and a
>>> "reverse", to return the elements of a list. Would either of those be
>>> an equivalent?
>>>
>>
>> Not without an "apply" mechanism used for function / method / operator
>> invocations. Which is almost viable in Perl 6 since the parameters get
>> passed as a list --- except that the list is only visible within the
>> implementation, not at the call site (which is what "apply" does).
>>
>> --
>> brandon s allbery kf8nh   sine nomine
>> associates
>> allber...@gmail.com
>> ballb...@sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>
> ​


Re: Justification for the "reversed" instruction format

2016-09-08 Thread Trey Harris
Ah, nice, good to know my concern was unwarranted.

On Thu, Sep 8, 2016 at 3:04 PM Aaron Sherman  wrote:

> In Perl 6, we apply those constraints when you pass off the call to the
> ultimate recipient, and that's important because that recipient can have
> multiple signatures (and signatures can be added *after* you define the
> flip).
>
> For example:
>
> $ cat foo.p6
>
>
> sub flip() { -> $b, $a, |c { f($a, $b, |c) } }
>
> multi sub counter(Int $start, Int $end, :$by=1) {
> $start, *+$by ... $end
> }
> multi sub counter(Str $start, Str $end, :$by=1) {
> ($start.ord, *+$by ... $end.ord).map: {.chr}
> }
>
> my  = flip 
>
> say flip-counter  10,   2, :by(2);
> say flip-counter 'q', 'k', :by(2);
> say flip-counter 3.7,   1, :by(2);
>
> $ perl6 foo.p6
> (2 4 6 8 10)
> (k m o q)
> Cannot resolve caller counter(Int, Rat, Int); none of these signatures
> match:
> (Int $start, Int $end, :$by = 1)
> (Str $start, Str $end, :$by = 1)
>   in block  at foo.p6 line 3
>
>
>
>
>
> Aaron Sherman, M.:
> P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
> Toolsmith, developer, gamer and life-long student.
>
>
> On Thu, Sep 8, 2016 at 2:41 PM, Trey Harris  wrote:
>
>> On Thu, Sep 8, 2016 at 9:23 AM Aaron Sherman a...@ajs.com
>>  wrote:
>>
>> I don't know Haskell, but isn't flip just:
>>>
>>> sub flip() { -> $b, $a, |c { f($a, $b, |c) } }
>>>
>>> And then:
>>>
>>> perl6 -e 'sub flip() { -> $a, $b, |c { f($b, $a, |c) } }; my  =
>>> flip  yas(1,2,3)'
>>> 213
>>>
>>> Yes—but my worry about that was that it wouldn’t carry over signature
>> constraints and coercions as a specific argument-flipper sub written with
>> the same signature (flipped). Haskell does deep type inference, unlike Perl
>> 6, so simply writing flip f x y = f y x is sufficient to get exactly the
>> same behavior in constrained or coercive contexts.
>>
>>
>>> Aaron Sherman, M.:
>>> P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
>>> Toolsmith, developer, gamer and life-long student.
>>>
>>>
>>> On Wed, Sep 7, 2016 at 6:13 PM, Brandon Allbery 
>>> wrote:
>>>
 On Wed, Sep 7, 2016 at 6:08 PM, Parrot Raiser <1parr...@gmail.com>
 wrote:

> There is a "flip" in P6, to reverse the characters in a string, and a
> "reverse", to return the elements of a list. Would either of those be
> an equivalent?
>

 Not without an "apply" mechanism used for function / method / operator
 invocations. Which is almost viable in Perl 6 since the parameters get
 passed as a list --- except that the list is only visible within the
 implementation, not at the call site (which is what "apply" does).

 --
 brandon s allbery kf8nh   sine nomine
 associates
 allber...@gmail.com
 ballb...@sinenomine.net
 unix, openafs, kerberos, infrastructure, xmonad
 http://sinenomine.net

>>>
>>> ​
>>
>
>


Re: Justification for the "reversed" instruction format

2016-09-08 Thread Aaron Sherman
In Perl 6, we apply those constraints when you pass off the call to the
ultimate recipient, and that's important because that recipient can have
multiple signatures (and signatures can be added *after* you define the
flip).

For example:

$ cat foo.p6

sub flip() { -> $b, $a, |c { f($a, $b, |c) } }

multi sub counter(Int $start, Int $end, :$by=1) {
$start, *+$by ... $end
}
multi sub counter(Str $start, Str $end, :$by=1) {
($start.ord, *+$by ... $end.ord).map: {.chr}
}

my  = flip 

say flip-counter  10,   2, :by(2);
say flip-counter 'q', 'k', :by(2);
say flip-counter 3.7,   1, :by(2);

$ perl6 foo.p6
(2 4 6 8 10)
(k m o q)
Cannot resolve caller counter(Int, Rat, Int); none of these signatures
match:
(Int $start, Int $end, :$by = 1)
(Str $start, Str $end, :$by = 1)
  in block  at foo.p6 line 3





Aaron Sherman, M.:
P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
Toolsmith, developer, gamer and life-long student.


On Thu, Sep 8, 2016 at 2:41 PM, Trey Harris  wrote:

> On Thu, Sep 8, 2016 at 9:23 AM Aaron Sherman a...@ajs.com
>  wrote:
>
> I don't know Haskell, but isn't flip just:
>>
>> sub flip() { -> $b, $a, |c { f($a, $b, |c) } }
>>
>> And then:
>>
>> perl6 -e 'sub flip() { -> $a, $b, |c { f($b, $a, |c) } }; my  =
>> flip  yas(1,2,3)'
>> 213
>>
>> Yes—but my worry about that was that it wouldn’t carry over signature
> constraints and coercions as a specific argument-flipper sub written with
> the same signature (flipped). Haskell does deep type inference, unlike Perl
> 6, so simply writing flip f x y = f y x is sufficient to get exactly the
> same behavior in constrained or coercive contexts.
>
>
>> Aaron Sherman, M.:
>> P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
>> Toolsmith, developer, gamer and life-long student.
>>
>>
>> On Wed, Sep 7, 2016 at 6:13 PM, Brandon Allbery 
>> wrote:
>>
>>> On Wed, Sep 7, 2016 at 6:08 PM, Parrot Raiser <1parr...@gmail.com>
>>> wrote:
>>>
 There is a "flip" in P6, to reverse the characters in a string, and a
 "reverse", to return the elements of a list. Would either of those be
 an equivalent?

>>>
>>> Not without an "apply" mechanism used for function / method / operator
>>> invocations. Which is almost viable in Perl 6 since the parameters get
>>> passed as a list --- except that the list is only visible within the
>>> implementation, not at the call site (which is what "apply" does).
>>>
>>> --
>>> brandon s allbery kf8nh   sine nomine
>>> associates
>>> allber...@gmail.com
>>> ballb...@sinenomine.net
>>> unix, openafs, kerberos, infrastructure, xmonad
>>> http://sinenomine.net
>>>
>>
>> ​
>


Re: Justification for the "reversed" instruction format

2016-09-08 Thread Aaron Sherman
I don't know Haskell, but isn't flip just:

sub flip() { -> $b, $a, |c { f($a, $b, |c) } }

And then:

perl6 -e 'sub flip() { -> $a, $b, |c { f($b, $a, |c) } }; my  = flip
 yas(1,2,3)'
213


Aaron Sherman, M.:
P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
Toolsmith, developer, gamer and life-long student.


On Wed, Sep 7, 2016 at 6:13 PM, Brandon Allbery  wrote:

> On Wed, Sep 7, 2016 at 6:08 PM, Parrot Raiser <1parr...@gmail.com> wrote:
>
>> There is a "flip" in P6, to reverse the characters in a string, and a
>> "reverse", to return the elements of a list. Would either of those be
>> an equivalent?
>>
>
> Not without an "apply" mechanism used for function / method / operator
> invocations. Which is almost viable in Perl 6 since the parameters get
> passed as a list --- except that the list is only visible within the
> implementation, not at the call site (which is what "apply" does).
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>


Re: Justification for the "reversed" instruction format

2016-09-07 Thread Parrot Raiser
There is a "flip" in P6, to reverse the characters in a string, and a
"reverse", to return the elements of a list. Would either of those be
an equivalent?

On 9/6/16, Trey Harris  wrote:
> There’s a very common functional programming pattern, usually called flip;
> its implementation in Haskell is simply:
>
> flip   :: (a -> b -> c) -> b -> a -> cflip f x y =  f y x
>
> Getting the same behavior out of a bespoke function in Perl 6 would be easy
> for any particular case, but writing a general version of flip that would
> work universally with all binary operators would be a pain to get right
> (while maintaining *exactly* the same behavior and errors as the original
> in all conditions), wouldn’t it?
>
> If so, R is syntactic sugar, but very helpful syntactic sugar.
>
> On Tue, Sep 6, 2016 at 12:59 PM Aaron Sherman 
> wrote:
>
> Oh, and note that you can pass R'd reductions as if they were normal prefix
>> ops:
>>
>> $ perl6 -e 'sub dueet(, *@list) { op @list }; say dueet
>> :<[R-]>,
>> 1..100'
>> -4850
>>
>>
>>
>> On Tue, Sep 6, 2016 at 12:51 PM, Aaron Sherman 
>> wrote:
>>
>>>
>>>
>>> $ perl6 -e 'my @numbers = 1..100; say [-] @numbers; say [R-] @numbers'
>>> -5048
>>> -4850
>>>
>>> In general, it's kind of pointless with bare infix ops, as you can just
>>> reverse the arguments, but when reducing or the like, it becomes much
>>> more
>>> valuable.
>>>
>>>
>>>
>>> On Tue, Sep 6, 2016 at 12:43 PM, Parrot Raiser <1parr...@gmail.com>
>>> wrote:
>>>
 I've just stumbled across "reversed operators", e.g. say 4 R/ 12; # 3
 in the documentation. I'm curious to know why the language includes
 them? I'm having trouble understanding where they would be useful.

>>>
>>>
>> ​
>


Re: Justification for the "reversed" instruction format

2016-09-07 Thread Brandon Allbery
On Wed, Sep 7, 2016 at 6:08 PM, Parrot Raiser <1parr...@gmail.com> wrote:

> There is a "flip" in P6, to reverse the characters in a string, and a
> "reverse", to return the elements of a list. Would either of those be
> an equivalent?
>

Not without an "apply" mechanism used for function / method / operator
invocations. Which is almost viable in Perl 6 since the parameters get
passed as a list --- except that the list is only visible within the
implementation, not at the call site (which is what "apply" does).

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: Justification for the "reversed" instruction format

2016-09-07 Thread Trey Harris
There’s a very common functional programming pattern, usually called flip;
its implementation in Haskell is simply:

flip   :: (a -> b -> c) -> b -> a -> cflip f x y =  f y x

Getting the same behavior out of a bespoke function in Perl 6 would be easy
for any particular case, but writing a general version of flip that would
work universally with all binary operators would be a pain to get right
(while maintaining *exactly* the same behavior and errors as the original
in all conditions), wouldn’t it?

If so, R is syntactic sugar, but very helpful syntactic sugar.

On Tue, Sep 6, 2016 at 12:59 PM Aaron Sherman 
wrote:

Oh, and note that you can pass R'd reductions as if they were normal prefix
> ops:
>
> $ perl6 -e 'sub dueet(, *@list) { op @list }; say dueet :<[R-]>,
> 1..100'
> -4850
>
>
>
> On Tue, Sep 6, 2016 at 12:51 PM, Aaron Sherman 
> wrote:
>
>>
>>
>> $ perl6 -e 'my @numbers = 1..100; say [-] @numbers; say [R-] @numbers'
>> -5048
>> -4850
>>
>> In general, it's kind of pointless with bare infix ops, as you can just
>> reverse the arguments, but when reducing or the like, it becomes much more
>> valuable.
>>
>>
>>
>> On Tue, Sep 6, 2016 at 12:43 PM, Parrot Raiser <1parr...@gmail.com>
>> wrote:
>>
>>> I've just stumbled across "reversed operators", e.g. say 4 R/ 12; # 3
>>> in the documentation. I'm curious to know why the language includes
>>> them? I'm having trouble understanding where they would be useful.
>>>
>>
>>
> ​


Re: Justification for the "reversed" instruction format

2016-09-06 Thread Aaron Sherman
Oh, and note that you can pass R'd reductions as if they were normal prefix
ops:

$ perl6 -e 'sub dueet(, *@list) { op @list }; say dueet :<[R-]>,
1..100'
-4850



On Tue, Sep 6, 2016 at 12:51 PM, Aaron Sherman 
wrote:

>
>
> $ perl6 -e 'my @numbers = 1..100; say [-] @numbers; say [R-] @numbers'
> -5048
> -4850
>
> In general, it's kind of pointless with bare infix ops, as you can just
> reverse the arguments, but when reducing or the like, it becomes much more
> valuable.
>
>
>
> On Tue, Sep 6, 2016 at 12:43 PM, Parrot Raiser <1parr...@gmail.com> wrote:
>
>> I've just stumbled across "reversed operators", e.g. say 4 R/ 12; # 3
>> in the documentation. I'm curious to know why the language includes
>> them? I'm having trouble understanding where they would be useful.
>>
>
>


Re: Justification for the "reversed" instruction format

2016-09-06 Thread Aaron Sherman
$ perl6 -e 'my @numbers = 1..100; say [-] @numbers; say [R-] @numbers'
-5048
-4850

In general, it's kind of pointless with bare infix ops, as you can just
reverse the arguments, but when reducing or the like, it becomes much more
valuable.



On Tue, Sep 6, 2016 at 12:43 PM, Parrot Raiser <1parr...@gmail.com> wrote:

> I've just stumbled across "reversed operators", e.g. say 4 R/ 12; # 3
> in the documentation. I'm curious to know why the language includes
> them? I'm having trouble understanding where they would be useful.
>


Justification for the "reversed" instruction format

2016-09-06 Thread Parrot Raiser
I've just stumbled across "reversed operators", e.g. say 4 R/ 12; # 3
in the documentation. I'm curious to know why the language includes
them? I'm having trouble understanding where they would be useful.