Defining a type that inherits methods

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Defining a type that inherits methods

Jérémy Béjanin
I know that it is not possible to subtype concrete types, but is it possible in some other way to create a type that behave exactly like an existing concrete type (in my case a Matrix) such that it would keep all the methods associated with it, but would still dispatch when a more specific (ie specific to that new type) method exists?

I searched on the mailing list but could not find anything.

Thanks,
Jeremy
Reply | Threaded
Open this post in threaded view
|

Re: Defining a type that inherits methods

Kristoffer Carlsson
This is the issue you are looking for: https://github.com/JuliaLang/julia/issues/9821

On Saturday, October 29, 2016 at 5:54:04 PM UTC+2, Jérémy Béjanin wrote:
I know that it is not possible to subtype concrete types, but is it possible in some other way to create a type that behave exactly like an existing concrete type (in my case a Matrix) such that it would keep all the methods associated with it, but would still dispatch when a more specific (ie specific to that new type) method exists?

I searched on the mailing list but could not find anything.

Thanks,
Jeremy
Reply | Threaded
Open this post in threaded view
|

Re: Defining a type that inherits methods

Chris Rackauckas
In reply to this post by Jérémy Béjanin
Functions shouldn't be written for concrete types and instead for abstract types. If you write your function for AbstractMatrix and then make your type <: AbstractMatrix, this will work naturally. Making the type declarations on a function too strict doesn't help performance anyways.

On Saturday, October 29, 2016 at 8:54:04 AM UTC-7, Jérémy Béjanin wrote:
I know that it is not possible to subtype concrete types, but is it possible in some other way to create a type that behave exactly like an existing concrete type (in my case a Matrix) such that it would keep all the methods associated with it, but would still dispatch when a more specific (ie specific to that new type) method exists?

I searched on the mailing list but could not find anything.

Thanks,
Jeremy