-
-
Save hoelzro/06ebf55b6b679ce4cb16 to your computer and use it in GitHub Desktop.
Real world use case for COERCE
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
Let's say there are two Matrix classes: Matrix::PP and Matrix::Blas. They are implemented independently of each other, but have a mostly compatible interface. | |
Now let's suppose I am using a module that returns a Matrix::PP ($pp-matrix), and I want to use it to perform some calcualtions. Pure-Perl 6 matrix calculations will be slower than using Matrix::Blas (which is backed by libblas), so I want to convert between the two. | |
I can't call $pp-matrix.Matrix::Blas, because Matrix::PP doesn't know about Matrix::Blas. I also can't do Matrix::Blas($pp-matrix), because even if Matrix::Blas overrides invoke(), it has no knowledge of Matrix::PP. | |
COERCE could solve this. Granted, I could just define pp-to-blas(Matrix::PP $) returns Matrix::Blas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment