On 03/17/2014 05:19 PM, Damian Conway (via RT) wrote:
# New Ticket Created by  Damian Conway
# Please include the string:  [perl #121454]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=121454 >


On the 2014.01 release of Rakudo, this works as expected:

     subset Zero of Int where 0;
     subset One  of Int where 1;

     multi fib (Zero)    { 1 }
     multi fib (One)     { 1 }
     multi fib (Int $n)  { fib($n-1) + fib($n-1) }

     say fib(3);

And we can then reduce the syntactic load by "inlining" the constraint:

     multi fib (0)       { 1 }
     multi fib (1)       { 1 }
     multi fib (Int $n)  { fib($n-1) + fib($n-1) }

     say fib(3);

Which also works under 2014.01.

Or we could have optimized the syntax with a junctive constraint instead:

     subset ZeroOne of Int where 0|1;

     multi fib (ZeroOne) { 1 }
     multi fib (Int $n)  { fib($n-1) + fib($n-1) }

     say fib(3);

Which also works under 2014.01.

So then I wanted to use the final syntactic optimization: once again
"inlining" the constraint:

     multi fib (0|1)     { 1 }
     multi fib (Int $n)  { fib($n-1) + fib($n-1) }

     say fib(3);

But that doesn't even compile. :-(
I believe it should.

As I read the specs,

multi fib(0|1) { 1 }

would be short for

multi fib(Junction $ where 0|1) { 1 }

which I believe doesn't do what you want.

Cheers,
Moritz

Reply via email to