A small update - I tried to simplify my example, but I removed too much.
This version is easy, it's just:
type SQLFoo{T <: AbstractModel}
model_name::Type{T}
end
What I'm looking for is having optional args, such as:
type SQLFoo{T <: AbstractModel}
model_name::Type{T}
bar::Bool
SQLFoo(T; bar = true) = new(model_name, bar)
end
Is this possible?
vineri, 10 iunie 2016, 20:21:18 UTC+2, Adrian Salceanu a scris:
>
> Hi,
>
> I don't know how to code this, any help appreciated.
>
> I want to have a concrete type that has a field referencing any of the
> subtypes of an(other) abstract type. How would I write that?
>
> This is one of my many attempts:
>
> type SQLFoo{T <: AbstractModel}
> model_name::Type{T}
>
>
> SQLFoo(model_name) = new(model_name)
> end
>
>
> julia> issubtype(Repo, AbstractModel)
> true
>
> julia> SQLFoo(Repo)
> ERROR: MethodError: `convert` has no method matching convert(::Type{SQLFoo
> {T<:AbstractModel}}, ::Type{Repo})
> This may have arisen from a call to the constructor SQLFoo{T<:
> AbstractModel}(...),
> since type constructors fall back to convert methods.
> Closest candidates are:
> call{T}(::Type{T}, ::Any)
> convert{T}(::Type{T}, ::T)
> in call at essentials.jl:56
>
>
> Thanks,
> -- Adrian
>