Daniel, Don't use the third choice -- one of the great things about working with Julia is that parametric or conditioning aspects of a multifaceted design can be actual parameters or typed in such a way that details of sub-specification become avenues of dispatch.
You mention "it would be handy to dispatch on the sequence" -- look no further, go with that as a part of your design. If you store the sequence value as a / one of the type parameter[s] then dispatching will happen for you. Storing the sequence as a field, maybe as an @enum looses you simplicity, so, of those three choices, the 3rd. You can use integer values (123, 132, 213... or whatever sequences are useful) for the e.g. SEQ parameter. The number of sequences is quite limited, so that is a reasonable way to go. And I defer to others on modelling with tensors. 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 >
