What I would like to do is create my own map which shares the same fields and methods as a FunctionMap, but to which I can add other methods (e.g. an inverse). For example, I would like to do something like this
where MyMap inherits all methods from FunctionMap except \, which I define myself. The above code does not work, and I get a complaint of LoadError: LoadError: invalid subtyping in definition of MyMap.
For some more relevant information on why this is intentionally disallowed, see the Types section in the manual:
One particularly distinctive feature of Julia’s type system is that concrete types may not subtype each other: all concrete types are final and may only have abstract types as their supertypes. While this might at first seem unduly restrictive, it has many beneficial consequences with surprisingly few drawbacks. It turns out that being able to inherit behavior is much more important than being able to inherit structure, and inheriting both causes significant difficulties in traditional object-oriented languages.
It’s been over 2 years since this thread, and “invalid subtyping” is still about the most useless Julia error I’ve seen. The stracktrace has come a LONG way since pre 1.0 releases in terms of info and speed, but this error seriously needs addressed, considering it’s at the root of OOP practices.
I am not sure why you think this. The error message is telling you that you are trying to define a subtype relationship that is not allowed in Julia (so it is invalid). I find it concise and informative.
What would you prefer instead?
(also, please don’t necro very old topics in the future)
Invalid subtyping seems like it could mean any number of things, such as “subtyping concrete types is perfectly ok, but you did it the wrong way, somehow.” Or that there’s something special or weird about that particular parent type that prevented subtyping, and that could be fixed. I would think that I had to tweak things a bit and try again, look through examples somewhere, and scratch my head a lot.
“Subtyping from concrete types is not possible” makes it really clear what’s wrong.
I think that because it is. I’m not saying there’s an easy fix, I but I don’t see how you can just say
The error message is telling you that you are trying to define a subtype relationship that is not allowed in Julia (so it is invalid).
You may as well have just read off the error statement. By that logic, a seg fault is just as informative. There are plenty of ways to “invalidly” subtype an abstract type. It would be helpful to see a more descriptive stack trace in this case, where possible.
I could start a new topic, sure, but why? It’s the same error, and it hasn’t been addressed AFAIC. Creating a new thread would create two unique pages for others to find eventual answers / solutions / etc.