If you are not dispatching on the type, why not allow the parameter to be 
duck typed? 
sometimes union typealiases can be helpful

typealias StringOrSymbol Union(String, Symbol)

test(x::StringOrSymbol) = symbol(x)


On Tuesday, February 11, 2014 10:44:56 PM UTC-5, Fil Mackay 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:>
> > 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:>
>> > 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.
>>>
>>>
>>
>

Reply via email to