This is a pretty typical pattern for Julia, as you're finding. My understanding is that this was a design choice: there are very few automatic conversions between types in Julia, and if anything looks like it was automatically converted, it was probably a side effect of multiple dispatch on an abstract type or because of an extra definition like the one I gave you.
If you could be more explicit about the problem you're trying to solve, you might get a better answer. There are ways people have gotten around this, but only with certain patterns (e.g., wrapper types). Cheers, Kevin On Tuesday, February 11, 2014, Fil Mackay <[email protected]> wrote: > Thanks for the reply Kevin. > > Unfortunately this is a routine pattern that I'm hitting, I was hoping for > a more general solution than adding a lot of extra overloads.. > > > On Wed, Feb 12, 2014 at 10:36 AM, Kevin Squire > <[email protected]<javascript:_e(%7B%7D,'cvml','[email protected]');> > > wrote: > >> Hi Fil, >> >> The way to do that in Julia is simply to define another version of the >> function, which does the conversion and passes that on to the "main" >> version of the function: >> >> test(str::String) = test(symbol(str)) >> >> Cheers, >> Kevin >> >> >> On Tue, Feb 11, 2014 at 3:30 PM, Fil Mackay >> <[email protected]<javascript:_e(%7B%7D,'cvml','[email protected]');> >> > wrote: >> >>> Just wondering if there is an operator to easily perform known >>> conversion. Say I have a function that takes a Symbol, and I want it to >>> accept a String as well: >>> >>> function test(s::Symbol) >>> end >>> >>> What I want to do is say, "yes I know this is not a Symbol - so please >>> convert() it" >>> >>> mystr = "foo" >>> test(mystr::Symbol) >>> >>> This would translate to: >>> >>> mystr = "foo" >>> test(convert(Symbol, mystr)) >>> >>> Is there any such operator? I would have thought doing this with the >>> current type assert would make sense? >>> >>> Regards, Fil. >>> >>> >> >
