Last active
September 20, 2017 20:15
-
-
Save grondilu/996c4d4b8911d4b3ddb5d6fdc095e488 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit role Algebra; | |
proto method ADD($) {*} | |
multi method ADD(Real $) {...} | |
multi method ADD(::?CLASS $) {...} | |
proto method MULTIPLY($) {*} | |
multi method MULTIPLY(::?CLASS $) {...} | |
multi method MULTIPLY(Real $) {...} | |
multi prefix:<->(::?CLASS $a) { (-1)*$a } | |
multi infix:<+>(::?CLASS $a, ::?CLASS $b) { $a.ADD($b) } | |
multi infix:<->(::?CLASS $a, ::?CLASS $b) { $a.ADD($b.MULTIPLY(-1)) } | |
multi infix:<*>(::?CLASS $a, ::?CLASS $b) { $a.MULTIPLY($b) } | |
multi infix:<*>(Real $a, ::?CLASS $b) { $b.MULTIPLY($a) } | |
multi infix:<*>(::?CLASS $a, Real $b) { $a.MULTIPLY($b) } | |
multi infix:</>(::?CLASS $a, Real $b) { $a.MULTIPLY(1/$b) } | |
multi infix:<**>(::?CLASS $a, 0) { 1 } | |
multi infix:<**>(::?CLASS $a, 1) { $a } | |
multi infix:<**>(::?CLASS $a, UInt $n) { ($a*$a)**($n div 2) * $a**($n mod 2) } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment