Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface inheritance: use abstract types rather than symbols for optional components? #33

Open
rafaqz opened this issue Oct 25, 2023 · 6 comments

Comments

@rafaqz
Copy link
Owner

rafaqz commented Oct 25, 2023

Each optional component would (hidden in the macro) define the abstract type like:

abstract type SomeInterface_option <: SomeInterface end

We could make it nicer looking, but that's the direct translation from what we have now

First we can just inherit the main interface

@interface NewInterface <: BaseInterface NewObject conditions 

But we could also inherit the optional component, which itself inherits the interface:

@interface NewInterface <: BaseInterface_opional_thing NewObject conditions 

We would test the interface by iterating over supertype until we hit AbstractInterface then working backwards, so the basal interface is tested first. When @@implements has multiple options, we would take the union of the interfaces to test at each step to avoid duplicating any tests..

But... what we really want is a hack for multiple inheritance:

@interface NewInterface <: Union{BaseInterface_option,SomeInterface} NewType conditions

Where we would drop the real inheritance and instead write something like:

abstract type NewInterface{T} <: Interface{T} end
inherits(::Type{<:NewInterface}) = (BaseInterface_option, SomeInterface)

Then all tests and trait queries would recurse over inherits(T) if a trait is false for T.

@gdalle
Copy link
Collaborator

gdalle commented Oct 30, 2023

I agree that inheriting interfaces is a key ingredient (see our recent Discourse discussion).
Note that it is already possible at the moment, simply by adding Interfaces.test of the parent interface as a mandatory condition. So the key question is what we hope to achieve with a different syntax / implementation.

@rafaqz
Copy link
Owner Author

rafaqz commented Oct 30, 2023

Yes its possible in the testing, but you don't get any traits to check that you passed it. The idea is that both tests and traits would be inherited automatically.

@gdalle gdalle changed the title Interface iheritance: use abstract types rather than symbols for optional components? Interface inheritance: use abstract types rather than symbols for optional components? Oct 31, 2023
@rafaqz
Copy link
Owner Author

rafaqz commented Nov 8, 2023

@gdalle I just realised having inheritance for options means we have to define the NamedTuple of options inside the macro so we can get the keys to define abstract types for them. So your changes allowing us to move objects out of the macro wont be able to be used.

@gdalle
Copy link
Collaborator

gdalle commented Nov 8, 2023

I'm kind of keen on that change, because hypothetically large interfaces could even span several code files

@rafaqz
Copy link
Owner Author

rafaqz commented Nov 9, 2023

Sure, I guessed as much.

But: how do we get the NamedTuple keys into the macro as an expression. We cant inspect a variable in a macro and we cant define types later at runtime.

(You may need to choose nice layout or iheritance... or just move individual option functions to files and make all your options single lines calling those functions)

@gdalle
Copy link
Collaborator

gdalle commented Nov 9, 2023

If there's a choice I definitely go for inheritance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants