Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ahalbert/b2714e33f15d6e2b3aa9944ef6c1867d to your computer and use it in GitHub Desktop.
Save ahalbert/b2714e33f15d6e2b3aa9944ef6c1867d to your computer and use it in GitHub Desktop.
multi sub infix:<+>(Unit $x, Unit $y) {
if (not $x.isSameUnit($y)) {die "Units do not match.";}
return Unit.new(magnitude => $x.magnitude + $y.magnitude, units => $x.units);
}
my $a = Units::Unit.new(magnitude => 1.2, units => ("m" => 1));
my $b = Units::Unit.new(magnitude => 5.0, units => ("m" => 1));
say $a + $b;
ERROR:
Cannot call Numeric(Units::Unit: ); none of these signatures match:
(Mu:U \v: *%_)
in block <unit> at t/units.t line 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment