How about
immutable MyType{T:Real}
x::T
v::Vector{T}
s::String
function MyType(x, v, s)
x = subtractpi(x)
v = map(subtractpi, v)
new(x, v, s)
end
end
MyType{T1:Real, T2:Real}(x::T1, v::Vector{T2}, s::String) =
(T=promote_type(T1,T2); MyType{T}(x, v,
Thanks for your quick response! I have a couple questions/concerns about
your implementation:
- MyType(1, [2, 3], xyz) fails requirement #2
- MyType(1, [2, 10], xyz) throws InexactError()
- Does the declaration s::String cause the ambiguities described in the FAQ
here
Thanks for your quick response! I have a couple questions/concerns about
your implementation:
- MyType(1, [2, 3], xyz) fails requirement #2
MyType{T1:Real, T2:Real}(x::T1, v::Vector{T2}, s::String) =
(T=promote_type(T1,T2,Float64); MyType{T}(x, v, s))
If you want to keep Float16, etc this
it should be noted that there's nothing inherently wrong or bad about
using non-concrete type specifications in type declarations. it does,
however, limit certain optimizations that might provide performance
benefits, and may be especially important for native numerical types.
On Wed Nov 26 2014