ConcreteStructs.@concrete
— Macro@concrete struct
@concrete mutable struct
@concrete terse struct
@concrete terse mutable struct
The @concrete
macro makes non-concrete structs concrete, saving the boilerplate of making type parameters. The terse
keyword causes the types to show without their parameters while in :compact => true
mode of an IOContext
.
Examples
julia> using ConcreteStructs
julia> @concrete struct AB
a
b
end
julia> ab = AB("hi", 1+im)
AB{String,Complex{Int64}}("hi", 1 + 1im)
julia> @concrete terse mutable struct CDE{D} <: Number
d::D
c
e::Symbol
end
julia> cde = CDE(1f0, (1,2.0), :yo)
CDE(1.0f0, (1, 2.0), :yo)
julia> typeof(cde)
CDE{Float32,Tuple{Int64,Float64}}
julia> @concrete terse struct FGH{T,N,G<:AbstractArray{T,N}} <: AbstractArray{T,N}
f
g::G
h::T
end
julia> Base.size(x::FGH) = size(x.g); Base.getindex(x::FGH, i...) = getindex(x.g[i...])
julia> fgh = FGH(nothing, [1,2,3], 4)
3-element FGH:
1
2
3
julia> typeof(fgh)
FGH{Int64,1,Array{Int64,1},Nothing}