BinaryTraits.jl icon indicating copy to clipboard operation
BinaryTraits.jl copied to clipboard

Single macro for defining a trait and its required interfaces

Open tk3369 opened this issue 4 years ago • 2 comments

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 avatar Apr 13 '20 03:04 tk3369

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.

tk3369 avatar Apr 22 '20 06:04 tk3369

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

JeffreySarnoff avatar May 18 '20 02:05 JeffreySarnoff