Thanks all for your input, I realize now this is still somewhat of a gray 
area. What I ended up doing was just adding a couple convert methods, and a 
promotion rule. It's a relatively simple type, so that was sufficient for 
my purposes. The tip to use a parametric type for Arrays was particularly 
helpful.

On Tuesday, March 17, 2015 at 7:03:44 AM UTC-4, Kristoffer Carlsson wrote:
>
> This is something I thought a lot about recently. Basically, I want to 
> have the exact functionality of a concrete type and be able to call all 
> function that takes the type but I also want to be able to dispatch 
> differently if I want. And I don't want to manually have to copy all the 
> methods.
>
> In summary, dispatch on typealias.
>
> I see this has been discussed before:
>
> https://groups.google.com/forum/#!msg/julia-dev/v8B1tI_NB5E/tk98D0iKopYJ
>
> https://github.com/JuliaLang/julia/pull/3292
>
> I realize this is basically subtyping from a concrete type which seems to 
> be a big nono but there would be so much nice things you could do with this.
>
> On Tuesday, March 17, 2015 at 11:02:17 AM UTC+1, Mauro wrote:
>>
>> >  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 
>>
>> There is also the Units.jl package, which may be of use? 
>>
>> >    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. 
>>
>> This is a only partially solved problem, as far as I know.  How do I 
>> wrap a datatype without having to re-implement all its methods. 
>> Sometimes this can be done through subtyping, but not always. 
>>
>> One approach is to use a macro to delegate methods to one of the fields 
>> of the datatype: 
>>
>> https://github.com/JuliaLang/DataStructures.jl/search?utf8=%E2%9C%93&q=delegate
>>  
>> https://github.com/JuliaLang/julia/pull/3292 
>>
>> For relatively simple number types, as in your case here, it might be 
>> better to manually hook into the "conversion and promotion" framework of 
>> Julia: 
>> http://docs.julialang.org/en/latest/manual/conversion-and-promotion/ 
>>
>

Reply via email to