You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the documentation, there is a section explaining how to "fake" inheritance using implicit typecasting. This is somewhat misleading since inheritance is transitive, but implicit typecasting is not.
For instance, in Java, an ArrayList is a kind of List which is itself a kind of Iterable. Consequently, you can pass an ArrayList object to any function that accepts an Iterable parameter. But if you tried to imitate this in Asymptote by creating types ArrayList, List, and Iterable, together with implicit typecasts ArrayList -> List and List -> Iterable, you would still not be able to pass an ArrayList to a function that expects an Iterable parameter:
structIterable { }
structList { }
Iterable operatorcast(List L) { return null; }
structArrayList { }
List operatorcast(ArrayList L) { return null; }
voiddoNothing(Iterable i) { }
ArrayList L = new ArrayList;
doNothing((List)L); // worksdoNothing(L); // does not work (but would if implicit casting were transitive)
I see two potential solutions to this issue:
(Recommended) Remove or amend the section in the documentation about imitating inheritance. (This technique doesn't seem to have been used much, and without transitivity it's not useful for complex hierarchies.)
Make implicit casting transitive. Basically, this would involve making the it so that if you have, e.g., implicit cast operators guide -> path and path -> path[], you'd automatically get an implicit path operator guide -> path[] (it would no longer need to be defined explicitly in plain_paths.asy). This sounds nice, but there's a catch: If you also had implicit casts guide -> guide[] and guide[] -> path[], you'd end up with an ambiguous "casting route" and go back to needing an explicitly defined guide -> path[]. Even worse, someone could have code that was working perfectly well but then broke because someone introduced a new cast guide -> guide[] and therefore made the existing code ambiguous. This last issue — the great potential for very sensible changes to break very sensible downstream code — is why I am skeptical of introducing transitivity, even if it could be done easily (which I'm guessing it could not).
The text was updated successfully, but these errors were encountered:
In the documentation, there is a section explaining how to "fake" inheritance using implicit typecasting. This is somewhat misleading since inheritance is transitive, but implicit typecasting is not.
For instance, in Java, an
ArrayList
is a kind ofList
which is itself a kind ofIterable
. Consequently, you can pass an ArrayList object to any function that accepts an Iterable parameter. But if you tried to imitate this in Asymptote by creating typesArrayList
,List
, andIterable
, together with implicit typecastsArrayList -> List
andList -> Iterable
, you would still not be able to pass an ArrayList to a function that expects an Iterable parameter:I see two potential solutions to this issue:
guide -> path
andpath -> path[]
, you'd automatically get an implicit path operatorguide -> path[]
(it would no longer need to be defined explicitly inplain_paths.asy
). This sounds nice, but there's a catch: If you also had implicit castsguide -> guide[]
andguide[] -> path[]
, you'd end up with an ambiguous "casting route" and go back to needing an explicitly definedguide -> path[]
. Even worse, someone could have code that was working perfectly well but then broke because someone introduced a new castguide -> guide[]
and therefore made the existing code ambiguous. This last issue — the great potential for very sensible changes to break very sensible downstream code — is why I am skeptical of introducing transitivity, even if it could be done easily (which I'm guessing it could not).The text was updated successfully, but these errors were encountered: