Mybe you're looking for this pattern: type Foo{T <: String} a::T b::T end Foo(a::String, b::String) = Foo(promote(a,b)...) If you don't know promote, here's an excerpt from help() julia> help(promote) Base.promote(xs...)
Convert all arguments to their common promotion type (if any), and return them all (as a tuple). Am Donnerstag, 5. März 2015 17:55:40 UTC+1 schrieb Benjamin Deonovic: > > Moving a post from julia issues to here since it is more appropriate: > https://github.com/JuliaLang/julia/issues/10408 > > If I am making a function or composite type that involves floating point > numbers, should I enforce those numbers to be Float64 or FloatingPoint? I > thought > it should be FloatingPoint so that the function/type will work with any > kind of floating point number. However, several julia packages enforce > Float64 (e.g. Distributions package Multinomial distribution) and so I run > into problems and have to put in a lot of converts in my code to Float64. Am > I doing this wrong? I'm quite new to julia > > > I don't have any intention to use non Float64 floatingpoints numbers, I'm > just trying to write good code. I saw a lot of examples where people > recommended to to use Integer rather than Int64 or String rather than > ASCIIString, etc. I'm just trying to be consistent. I'm fine just using > Float64 if that is the appropriate approach here. >