-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add boilerplate outer constrcutors to EossParam
s
#45
Labels
design doc
List possible ways of implementations and see what's the best
Comments
singularitti
added
the
design doc
List possible ways of implementations and see what's the best
label
Aug 17, 2020
But now I found I could just write (::Type{T})(arr::AbstractVector) where {T<:EossParam} = T{eltype(arr)}(arr...)
(::Type{T})(args...) where {T<:EossParam} = T([args...]) and it works! julia> BirchMurnaghan3rd(1,2,3.0)
BirchMurnaghan3rd{Float64}
v0 = 1.0
b0 = 2.0
b′0 = 3.0
e0 = 0.0
julia> BirchMurnaghan3rd([1,2,3.0])
BirchMurnaghan3rd{Float64}
v0 = 1.0
b0 = 2.0
b′0 = 3.0
e0 = 0.0 No need to rely on Also, there is no type-piracy on julia> methods(Type)
# 0 methods for generic function "(::Type)":
julia> methods(EossParam)
# 2 methods for generic function "(::Type)":
[1] (::Type{T})(arr::AbstractArray{T,1} where T) where T<:EossParam in EquationsOfStateOfSolids.Collections at ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:230
[2] (::Type{T})(args...) where T<:EossParam in EquationsOfStateOfSolids.Collections at ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:231 And directly call on julia> EossParam(1,2,3)
ERROR: TypeError: in Type{...} expression, expected UnionAll, got Type{EossParam{Int64}}
Stacktrace:
[1] EossParam{Int64}(::Array{Int64,1}) at ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:230
[2] EossParam{Int64}(::Int64, ::Vararg{Int64,N} where N) at ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:231
[3] EossParam(::Array{Int64,1}) at ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:230
[4] EossParam(::Int64, ::Vararg{Int64,N} where N) at ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:231
[5] top-level scope at none:0
julia> EossParam([1,2,3])
ERROR: TypeError: in Type{...} expression, expected UnionAll, got Type{EossParam{Int64}}
Stacktrace:
[1] EossParam{Int64}(::Array{Int64,1}) at ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:230
[2] EossParam{Int64}(::Int64, ::Vararg{Int64,N} where N) at ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:231
[3] EossParam(::Array{Int64,1}) at ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:230
[4] top-level scope at none:0
julia> FiniteStrainEossParam(1,2,3)
ERROR: TypeError: in Type{...} expression, expected UnionAll, got Type{FiniteStrainEossParam{Int64,Int64}}
...
julia> FiniteStrainEossParam([1,2,3])
ERROR: TypeError: in Type{...} expression, expected UnionAll, got Type{FiniteStrainEossParam{Int64,Int64} And it's fast, complete and no repetition of code! julia> methods(BirchMurnaghan3rd{Int})
# 4 methods for type constructor:
[1] BirchMurnaghan3rd(v0, b0, b′0) where T
@ EquationsOfStateOfSolids.Collections ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:46
[2] BirchMurnaghan3rd(v0, b0, b′0, e0) where T
@ EquationsOfStateOfSolids.Collections ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:46
[3] EossParam(arr::AbstractArray{T,1} where T) where T<:EquationsOfStateOfSolids.Collections.EossParam
@ EquationsOfStateOfSolids.Collections ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:257
[4] EossParam(args...) where T<:EquationsOfStateOfSolids.Collections.EossParam
@ EquationsOfStateOfSolids.Collections ~/.julia/dev/EquationsOfStateOfSolids/src/Collections.jl:258 |
singularitti
added a commit
that referenced
this issue
Aug 17, 2020
singularitti
added a commit
that referenced
this issue
Aug 17, 2020
Add boilerplate outer constrcutors to `EossParam`s as in #45
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the past I used to add outer constructors using
eval-quote
to types that are concrete subtypes of a type, that was slow to load and a bit o f ugly. Or I can list all concrete subtypes by hand, it's maybe a bit faster but it requires manual updating.The text was updated successfully, but these errors were encountered: