I just start to write the program so I may not have any code to post.
I want to define a position of a particle like
type particle{T}
pos::T
end
but I hope the type of pos can be limited rather than the supertype any
2015-10-15 20:51 GMT+08:00 Roger Luo <[email protected]>:
> It's like what if I want to define a 3-dimension linear space R^3 as an
> abstract type and the Array{Float,3} is a subtype-like type of the abstract
> type 3-dimension linear space?
>
> I want a linear space as abstract type and some subtypes that can do the
> linear algebra.
>
> 2015-09-25 20:36 GMT+08:00 Yichao Yu <[email protected]>:
>
>> I have some trouble understand your question.
>>
>> On Fri, Sep 25, 2015 at 8:22 AM, Roger Luo <[email protected]>
>> wrote:
>> > Thanks,I've read about the arrays,but just don't know how to define some
>> > existed type.
>>
>> You cannot redefine a type. Or do you mean how are certain existed
>> types implemented? For that you can just check out the source code.
>>
>> > though a type may be defined as:
>> > type a{T<:Integer}<:Real
>> > xxx
>> > end
>> >
>> > but that's will work in my function.I tried to pass different types
>> into a
>> > function, so I asked this question.
>> > still do not understand why can define a existed type become a subtype
>> of
>> > some other type?
>>
>> You cannot change the type inheritance of an existing type, period. As
>> Mauro pointed out, you are probably looking for something else. It
>> would be better if you can post the original problem you are trying to
>> solve.
>>
>> >
>> > 2015-09-25 15:11 GMT+08:00 Mauro <[email protected]>:
>> >>
>> >> Julia's parametric types are invariant (except tuples). To figure out
>> >> what that means have a read through
>> >>
>> >>
>> http://docs.julialang.org/en/release-0.4/manual/types/#parametric-composite-types
>> >>
>> >> > How to make Array{BigFloat,1}<:Array{Real,1}?
>> >>
>> >> This is always false (that is invariance). But presumably you want a
>> >> method which takes any Array with eltype<:Real, try something like:
>> >>
>> >> julia> f{T<:Real}(ar::Array{T,1}) = typeof(ar)
>> >> f (generic function with 1 method)
>> >>
>> >> julia> f(Array(BigFloat, 2))
>> >> Array{BigFloat,1}
>> >
>> >
>>
>
>