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

Implement parametric trait types #47

Closed tk3369 closed 4 years ago

tk3369 commented 4 years ago

This PR is to implement the idea as described in #23

An interesting artifact of switching to this design is that the commonly-used trait prefix types (Can, Is, Not, etc.) are predefined as aliases to Positive and Negative prefix types. In order to avoid polluting the namespace, they are defined in a submodule BinaryTraits.Prefix. The user just needs to import whatever they need like this:

using BinaryTraits.Prefix: Can, Cannot

Thinking further ahead, the prefix clause in @trait macro becomes a little redundant. It feels somewhat convenient though. So, I have kept the code and and make it auto-import the prefix types for now.

Cc: @KlausC @akels

codecov[bot] commented 4 years ago

Codecov Report

Merging #47 into master will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #47   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          239       241    +2     
=========================================
+ Hits           239       241    +2     
Impacted Files Coverage Δ
src/BinaryTraits.jl 100.00% <ø> (ø)
src/misc.jl 100.00% <ø> (ø)
src/assignment.jl 100.00% <100.00%> (ø)
src/interface.jl 100.00% <100.00%> (ø)
src/trait.jl 100.00% <100.00%> (ø)
src/types.jl 100.00% <100.00%> (ø)
src/utils.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0acedd6...7ec65aa. Read the comment docs.

tk3369 commented 4 years ago

Alright, this PR is pretty much ready to go. I'm planning to merge to master and announce to the community this weekend. Please review code if possible. Additional changes are listed as follows:

Renamed functions

While updating documentations, I realized that some functions are not consistently named. I have changed them as follows:

how do we refer to trait types?

I used to call the super-type a trait e.g. Fly would be a trait. Then, the positive and negative types were "can-type" and "cannot-type" (or "can-trait" or "cannot-trait"). Honestly, this naming scheme is quite awkward.

I realized that it's OK to just refer the positive and negative trait types as traits. So Can{Fly} is a trait and Cannot{Fly} is also a trait. Then, what do we call the abstract type Fly itself? I don't know. Suggestions welcome. For now, I have made the is_trait function to return true for all of them.