8000 GitHub - bhgomes/SubTypes.jl at v0.1.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

bhgomes/SubTypes.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SubTypes.jl

Stable Docs Latest Docs Travis Build Status

Custom Subtyping in Julia

Custom Subtype

To create a custom subtype define the following data

SubType{T, P, Flag}
#=
        ^  ^  ^
        1  2  3
1 => Underlying Type
2 => Predicate Data
3 => Type Flag
=#

and a predicate processing function

check_predicate(P, Val(Flag), x::T)

which checks if x::T should be of type SubType{T, P, Flag}. The flag is a way to mark the subtypes for overloading.

Predefined Custom Subtypes

The custom subtypes Constrained and ConstrainedSymbol are predefined in the module and they emulate set inclusion subtyping, i.e.

x::Constrained{T, S}  <=>  x.value::T in S

and ConstrainedSymbol is set inclusion for Symbol types. Inspiration for this type comes from this post by Mohamed Tarek @mohamed82008.

Helper Functions

This module also comes with these helper functions defined for terms and types:

eltype(::SubType{T}) = T
predicate(::SubType{T, P}) = P
flag(::SubType{T, P, Flag}) = Flag
support(::Constrained{T, S}) = S

Installation

To install, run the following in a Julia session:

]add SubTypes

Knowledge is Freedom.

About

Custom Subtyping in Julia

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages

0