tk3369 / BinaryTraits.jl

Can do or not? It's easy. See https://tk3369.github.io/BinaryTraits.jl/dev/
MIT License
53 stars 3 forks source link

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

Open tk3369 opened 4 years ago

tk3369 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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