Suppose I define a function on an abstract type A in Julia:
abstract A function mysum(a::A) ax + ay end
Implicitly, any subtype must have x and y fields for this function to work. Thus, the functions defined on A define the requirements for subtypes. These functions could be written anywhere, and one could imagine a situation where functions are much more complex and requirements are more difficult to detect. Is it possible to somehow declare requirements, a subtype of an abstract type must have, in addition to simply implicitly from functions?
This is similar to Julia # 6975 , but if it is not related to this, someone can clarify the difference.
Finally, why does someone want to use type union instead of an abstract type. The abstract type is more flexible and extensible, the union of types is fixed. for instance
Why is this:
type A x end type B x end typealias C Union{A,B}
Instead of this:
abstract C type A <: C x end type B <: C x end
source share