Skip to content

Structural Interfaces (not behavioral) #43083

Closed
@zot

Description

@zot

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} and Writable{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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions