Suppose I define a function on an abstract type A in Julia:
abstract A
function mysum(a::A)
a.x + a.y
end
Implicitly any subtype should have the fields x and y for this function to work. So the functions defined on A are what set the requirements for subtypes. These functions could be written anywhere and one can imagine a situation where the functions are much more complex and the requirements are harder to spot. Is there someway to declare the requirements a subtype of an abstract type must have besides just implicitly from functions?
This seems to be related to Julia#6975 but if its not related to that could someone clarify the difference.
Finally, why would anyone want to use a type union instead of an abstract type. The abstract type is more flexible and extensible, the type union is fixed. For example
Why 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