tk3369 / BinaryTraits.jl

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

Relax contract function argument to any tuple #21

Closed tk3369 closed 4 years ago

tk3369 commented 4 years ago

When battle-testing with AbstractArray interface, it becomes clear that some interface contracts needs to be specified with duck typing e.g. setindex!(x, v, i::Int) where the type of v is not specified.

The interface check is based upon a subtype check. For example, if the interface specifies that a function accepts Any, then any implementation that only supports a subtype would not be compliant because it does not cover all other types that falls under Any. This is related to the contra-variances. So, when the interface calls for duck typing, it actually need to refer to the Base.Bottom data type, which is the bottom-most data type of the type hierarchy. Hence, any function definition taking any type will make it compliant with the contract.

For that reason, the Contract.args field must accept a type that includes any data type + Bottom. But Bottom <: DataType is not true. To keep it simple, I have relaxed the typing from NTuple{N,DataType} to just any Tuple.