-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Structural Interfaces (not behavioral) #43083
Comments
Very related: #4935 |
True but structs and named tuples can be type compatible with many structural interfaces at once. |
Would this be actually desugared to a behavioural interface with inlined |
I don't think this should simply be sugar, I think it should be type information that can be checked with structinterface AStructuralInterface
a::Number
end Guarantees that
will work for any |
Should we convert this to a "Discussion"? |
I certainly think it's worth discussing! 😃 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I think it would be helpful if there were "structural interfaces" to express that a value is expected to have readable or writable fields of certain types when the value could also contain other fields (so the structural interface could be a subset of the value's type). Maybe something like
Readable{x::Int, y::String}
andWritable{z::Float64}
(those names would probably clash with a lot of code that's already out there). This is a way to sort of embrace Julia's duck typing within the type system (it's no coincidence that TypeScript's interfaces can contain fields). This isn't like Java's interfaces because it doesn't address methods but I think it would provide some important utility.This would let a function author indicate, "this function will fail if the input does not have an
x::Int
field," and IDEs could warn developers when they try to pass incompatible data to the function.This could help document data used in protocols, file formats, etc. but still allow developers the freedom to use structures or named tuples which contain more information than the function uses.
The text was updated successfully, but these errors were encountered: