TSa Thomas.Sandlass-at-barco.com |Perl 6| wrote:

In "24.28.1 abs" you define

  our ::?CLASS multi method abs ( $x: )

I would rather nail down the return type to 'Num where {$_ >= 0}'.
The latter might also get a nice name, e.g. Abs. This in turn would
make the abs multi method/sub kind of redundant.

I guess that the standard set of functions/methods mustn't contain
a norm as extension to the above.



I think I listed a single method of this class because it was mentioned in the synopses somewhere. That is, just gathering what is already stated, not fleshing it out yet.

Shouldn't abs return the same kind of class it was run on? That is, Int in this case, not Num. Should it be generic and simply work for all types that have the +/- concept? Count on member dot syntax deferring to sub calls to still allow $x.abs instead of abs($x) to work.

my Int $y = $x.abs;    # should be Int without complaint, not
 # coersion of Num back to Int.


For factoring out such things, we need to better define the "interfaces" that will be used for generic code. For example, we can have ispositive/isnegative tests without full ordering, and perhaps generic code that called .isnegative would be more efficient than comparing < 0 especially when you need to remember to turn 0 into the correct type.

--John

Reply via email to