我需要帮助来确定是否可以通过使用does
(或but
)的mixin方式使数学运算符重载正常工作,以避免以下歧义错误...这个模块:
unit module Physics::Error;
role Error is export {
has Real $.abs-error;
method negate {
...
}
}
multi prefix:<-> ( Error:D $right) is export {
...
}
用于此脚本的方式...
use Physics::Error;
my $x = 12.5 does Error(0.5);
my $z = -$x;
对 'prefix:<->(Rat+{Physics::Error::Error})' 的调用不明确;所有这些签名都匹配: (Rat:D \a) (Physics::Error::Error:D $right)
我希望我的自定义运算符始终能够不含歧义地获胜,然后实现核心操作和误差计算,最后返回 (Rat+{Physics::Error::Error})。
总的来说,是要进行数学运算,同时执行简单的误差计算。
is default
会有所帮助?https://docs.raku.org/type/Routine#index-entry-is_default_(Routine) - Elizabeth Mattijsenis default
就是这个作用 - 谢谢你们两位(附注:楼主编辑后更明确了目标) - librasteve