Skip to content

Instantly share code, notes, and snippets.

@Ovid

Ovid/fahr.p6 Secret

Created January 8, 2016 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ovid/fe0847a882ceda440271 to your computer and use it in GitHub Desktop.
Save Ovid/fe0847a882ceda440271 to your computer and use it in GitHub Desktop.
Defining my operator failed
class Fahrenheit {
has Real $.temperature is required;
method infix:<+>(Fahrenheit:D $a, Fahrenheit:D $b) {
return Fahrenheit.new( temperature => $a.temperature + $b.temperature );
}
}
my $t1 = Fahrenheit.new( temperature => 22 );
my $t2 = Fahrenheit.new( temperature => 34 );
say $t1 + $2;
# Cannot call Numeric(Fahrenheit: ); none of these signatures match:
# (Mu:U \v: *%_)
# in block <unit> at int.p6 line 11
@Ovid
Copy link
Author

Ovid commented Jan 8, 2016

Per arnsholt, I've tried this, but it failed with the same error:

class Fahrenheit {
    has Real $.temperature is required;
}

multi sub infix:<+>(Fahrenheit:D $a, Fahrenheit:D $b) {
    return Fahrenheit.new( temperature => $a.temperature + $b.temperature );
}

my $t1 = Fahrenheit.new( temperature => 22 );
my $t2 = Fahrenheit.new( temperature => 34 );
say $t1 + $2;

@Ovid
Copy link
Author

Ovid commented Jan 8, 2016

As pointed out, $2 was a typo :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment