So, I think that a proper solution here is for there to be a single method foo that has the desired parameter signature, and have that method return a single object which acts like / has the roles/interfaces of both of the return types that 'wantarray' would have chosen between. Therefore, each caller context can call foo() and use the result in the way it expects to. -- Darren Duncan

On 2015-03-19 4:00 PM, Tom Browder wrote (in private):
On Thu, Mar 19, 2015 at 5:53 PM, Darren Duncan <dar...@darrenduncan.net> wrote:
I think as a general principle, multi methods should dispatch entirely on
their parameter signatures, and dispatching on return type is just a bad
design that leads to trouble.  If you want different return types for

I don't disagree, Darren, but for the moment I'm trying to translate a
Perl 5 CPAN module to Perl 6 and trying to keep the API as close as
possible to the original.

On 2015-03-19 3:58 PM, Tobias Leich wrote:
The multi dispatcher *only* chooses the multi candidate by matching
arguments to parameters. The return type is not considered.

Btw, the syntax for returning an arrayish thing might be: method foo($a,
$b --> Positional) { ... }

Am 19.03.2015 um 23:53 schrieb Darren Duncan:
I think as a general principle, multi methods should dispatch entirely
on their parameter signatures, and dispatching on return type is just
a bad design that leads to trouble.  If you want different return
types for identical parameters, you should give those 2 versions
different method base names. -- Darren Duncan

On 2015-03-19 3:20 PM, Tom Browder wrote:
I need to replace the Perl 5 'wantarray' and think a multi method with
differing return types should do it.

So I've tried this:

multi method foo($a, $b --> {Num,Num}) { #... }
multi method foo($a, $b --> Num) { #... }

and get errors like:

Missing block
at Ellipsoid.pm:672
------> ethod to($lat1, $lon1, $lat2, $lon2 --> �{Rat, Rat})
    from test_ellipsoid.pl:12

I've tried parentheses, square brackets, and no grouping characters
instead of curly braces but that doesn't change the error.

Question:

How does one properly provide differing function return type signatures?

Reply via email to