I think the part that is making things difficult for me is that I'm not 
assuming Float64.  I could do it by calling the inner constructor, like you 
do in your example, but I think I'd have to explicitly give the element 
type:

EulerAngles{Float64, 321}([10.0, 20.0, 30.0])

I know that you can use an outer constructor so that the type of the 
arguments determines the type parameter used.  But it isn't clear how to do 
that if the arguments give only a subset of the type parameters, and the 
rest need to be given explicitly.  I was wondering if that is maybe just 
not possible.

In my original post, my [1.0, 2.0, 3.0] array is the Euler angles 
themselves.  I can see how that could be confused for the Euler sequence, 
so here I used [10.0, 20.0, 30.0] instead.

On Tuesday, August 25, 2015 at 11:11:34 PM UTC-5, Jeffrey Sarnoff wrote:
>
> Are you looking to do this?
>
> julia> type EulerRotation{I,J,K}
>           angles::Vector{Float64}
>        end
>
> julia> function getEulerAngleSeq(x::EulerRotation)
>            p = typeof(x).parameters
>            Float64[x.angles[i] for i in p]
>        end
> getEulerAngleSeq (generic function with 1 method)
>
> julia> testRotSeq321 = EulerRotation{3,2,1}([1.0,2.0,3.0])
> EulerRotation{3,2,1}([1.0,2.0,3.0])
>
> julia> getEulerAngleSeq(testRotSeq321)
> 3-element Array{Float64,1}:
>  3.0
>  2.0
>  1.0
>
> julia> testRotSeq132 = EulerRotation{1,3,2}([1.0,2.0,3.0])
> EulerRotation{1,3,2}([1.0,2.0,3.0])
>
> julia> getEulerAngleSeq(testRotSeq132)
> 3-element Array{Float64,1}:
>  1.0
>  3.0
>  2.0
>
>
>
> On Tuesday, August 25, 2015 at 11:29:08 PM UTC-4, [email protected] 
> wrote:
>>
>> Hi, everyone.
>>
>> I've been tinkering with creating a package for dealing with Euler 
>> angles, using a very recent build of v0.4.  Rather than just rehash 
>> Matlab's functions, I wanted to take advantage of the type system, to learn 
>> more about parametric types and constructors.
>>
>> I definitely want the Euler rotation sequence and the angles to be bound 
>> together.  One straightforward way to do this would of course be:
>>
>> type EulerAngles{T <: Number}
>>     seq::Int
>>     angles::Vector{T}
>> end
>>
>> Which would work fine, but I'd end up with a huge if block for every 
>> valid sequence.  So I thought I'd try moving the sequence into the type 
>> definition.  I think I would declare the type like this:
>>
>> type EulerAngles{T <: Number, s}
>>     angles::Vector{T}
>> end
>>
>> But then I can't figure out the best way to provide constructors for this 
>> type.  What I want is something like this:
>>
>> EulerAngles{321}([1.0, 2.0, 3.0])
>>
>> But I can't figure out how to get this to work.  Is this kind of 
>> constructor even possible with the type I showed above?
>>
>> I was able to get something very similar to work, by making functions 
>> that look like constructors with the sequence in their names, like this:
>>
>> EulerAngles321([1.0, 2.0, 3.0])
>>
>> Which works, but gives the impression that EulerAngles321 is actually a 
>> type.  But it seems that typealiases can't have constructors, and I get an 
>> error trying to define a typealias and a function with the same name.  Even 
>> with this limitation, though, this seems like an OK solution.
>>
>> If I really wanted to have types with those names, I could have an 
>> abstract EulerAngles type, and then have concrete types like 
>> EulerAngles321.  But that seems like overkill (in terms of the number of 
>> types I'd create).  Though it would work.
>>
>> Does anyone have any guidance on how to best approach this?
>>
>> Thanks for the help!
>>
>> Daniel
>>
>

Reply via email to