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

Single macro for defining a trait and its required interfaces #24

Open
tk3369 opened this issue Apr 13, 2020 · 2 comments
Open

Single macro for defining a trait and its required interfaces #24

tk3369 opened this issue Apr 13, 2020 · 2 comments

Comments

@tk3369
Copy link
Owner

tk3369 commented Apr 13, 2020

See https://discourse.julialang.org/t/ann-binarytraits-jl-a-new-traits-package/37475/5?u=tk3369

In a nutshell, the ideas are:

  1. do not allow anyone to add new interface functions to an existing trait.
  2. check the interface implementation correct as soon as the data type is assigned to a trait
@tk3369
Copy link
Owner Author

tk3369 commented Apr 22, 2020

The idea is to enforce consistency. The benefit is that a user would not accidentally assign and check a type, and then later change the contract. To do this, we will probably have to support a new syntax such that all interfaces are defined altogether in one place e.g.

@implement Can{Drive} by begin
    start(_)
    turn(_, direction::Float64)
    move(_, distance::Float64)
    stop(_)
end 

Then, either disallow the user from issuing another @implement Can{Drive} statement again, or else we could automatically check all assigned types against the new contract.

As for the 2nd point, it seems to be just a small convenience over two lines of code (@assign followed by @check). I don't think that is needed at the moment.

@JeffreySarnoff
Copy link

or maybe do so .. provide a seal_this_interface command/function/operation/macro which, when utilized, disallows, and until utilized, allows.

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

No branches or pull requests

2 participants