Skip to content

Instantly share code, notes, and snippets.

@MadcapJake
Created April 21, 2016 20:18
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 MadcapJake/1873f1519528bf5c626bbd49ea6d7b3f to your computer and use it in GitHub Desktop.
Save MadcapJake/1873f1519528bf5c626bbd49ea6d7b3f to your computer and use it in GitHub Desktop.
# No need for new/BUILD if you accept a longer instantiation
class FuzzyNum {
has Num $.i;
method gist { $!i.gist }
};
# Must be multi, otherwise overwrites all + operators
multi sub infix:<+>(FuzzyNum $a, FuzzyNum $b) {
FuzzyNum.new(i => $a.i + $b.i + rand ** rand)
}
my FuzzyNum $a .= new(i => 1e0);
my FuzzyNum $b .= new(i => 1e0);
# Not sure why WHAT doesn't work here but it doesn't
say $a;
say $b;
say $a + $b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment