Created
May 9, 2020 08:25
-
-
Save cesartl/20ce636fd7bef32ed416fa8e2e7b5f2b 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
interface Matrix22Monoid : Monoid<Matrix22> { | |
override fun empty(): Matrix22 = Matrix22.identity | |
override fun Matrix22.combine(b: Matrix22): Matrix22 { | |
val (l00, l01, l10, l11) = this | |
val (r00, r01, r10, r11) = b | |
return Matrix22( | |
l00 * r00 + l01 * r10, | |
l00 * r01 + l01 * r11, | |
l10 * r00 + l11 * r10, | |
l10 * r01 + l11 * r11 | |
) | |
} | |
} | |
fun Matrix22.Companion.monoid(): Monoid<Matrix22> = object : Matrix22Monoid {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment