Le lundi 16 mars 2015 à 13:00 -0700, Chris a écrit : > Hello, > > > I have written a bunch of Julia code with functions assuming a certain > variable (time) is a Float64 (really it's a Julian Date). I recently > decided it might be a good idea to introduce a custom JDate type, > which I defined as a subtype of FloatingPoint: > > > immutable JDate <: FloatingPoint > t::Float64 > end > > > My thinking being that this would help avoid ambiguity with my code, > as I sometimes work with other units of time (e.g. seconds) that are > also floating point numbers. Of course, this introduced a number of > problems in my existing code, including > 1. Arithmetic operators not defined for type JDate. My workaround > for this has thus far been to overload the operators to accept > JDate types. > 2. My functions not having methods that accept time as a JDate > type. My workaround for this has been to change the function > to accept time::FloatingPoint instead of time::Float64, but > this workaround does not work for Arrays. > I've read through the relevant parts of the documentation, although > I'm not sure how much actually stuck, since a good portion was over my > head. > > > In general, am I going about this the right way? If not, what should I > do differently? Is there any way to resolve the issue with Arrays, > besides creating another method that accepts Array{JDate,1}? I guess you should simply define your functions as f{T<:FloatingPoint}(a::Array{T}, ...) so that they accept arrays of any floating point type.
Other than that, looks like you're doing it right, though as Tom said using DateTime instead is probably a good idea. Regards