Standalone Abstract Type
Use @types with just a name to declare an abstract type:
@types Organism
isabstracttype (Organism)
Parametric abstract types are supported too:
@types Container{T}
isabstracttype (Container)
Abstract Type with Subtypes
Use > to define an abstract type and its concrete subtypes together:
@types Animal > (
Cat (lives:: Int ),
Dog (name:: String )
)
supertype (Cat), supertype (Dog)
(Cat(lives=9), Dog(name="Rex"))
Parametric Types
Type parameters and bounds work as normal Julia syntax inside {}:
@types Envelope{T} > (
Plain {T} (value:: T ),
Labelled {T, S <: AbstractString} (value:: T , label:: S )
)
Labelled {Int, String} (42 , "answer" )
Labelled{Int64, String}(value=42, label="answer")
Every subtype must declare its parent’s parameters — Plain{T}, not Plain. Omitting them is an error naming the type and the correct spelling:
@types Envelope{T} > (Plain (value:: T ),)
# ERROR: @types: `Plain` must declare its parent's type parameters: write `Plain{T}`
Nested Hierarchies
A subtype can itself be an abstract type with its own subtypes by using > again:
@types Animal2{T} > (
Mammal {T} (family:: T ),
Invertebrate{T} > (
Worm {T} (),
Insect {T, I <: Integer} (legs:: I , family:: T )
)
)
supertype (Invertebrate{Float64 }), supertype (Worm{Float64 })
(Animal2{Float64}, Invertebrate{Float64})
Worm {String} (), Insect {Float64, Int8} (6 , 1.0 )
(Worm{String}, Insect{Float64, Int8}(legs=6, family=1.0))
Abstract vs. Concrete
Parentheses decide whether a name becomes an abstract type or a concrete struct — the same rule at the top level and inside a hierarchy. A bare name is abstract; empty parentheses give a zero-field struct:
@types Tree > (
Branch, # abstract type Branch <: Tree end
Leaf (), # struct Leaf <: Tree end
)
isabstracttype (Branch), isabstracttype (Leaf)
Branch can then be extended later, either with another @types block or with <::
@types Twig (length:: Float64 ) <: Branch
supertype (Twig)
Single Concrete Type
Define a single struct without a hierarchy:
@types Point (x:: Float64 , y:: Float64 )
Point (1.0 , 2.0 )
To specify a supertype, use <::
@types Organism2
@types Bacterium (name:: String ) <: Organism2
supertype (Bacterium)