afaik, Julia does elegant -- but I have no insight into the situation at 
hand;  tossing this to  `@stefankarpinski`

On Tuesday, March 22, 2016 at 3:52:23 PM UTC-4, Bill Hart wrote:
>
> Thanks, that looks like an elegant solution if we can make it work. 
> Unfortunately it doesn't.
>
> I added the following function to Nemo:
>
> function promote_rule_exists{T1, T2}(::Type{T1}, ::Type{T2})
>    return Union{} != Base.promote_rule(T1, T2)
> end
>
> But when I do
>
> Nemo.promote_rule_exists(Nemo.Poly{Nemo.fmpz_poly}, Nemo.fmpz)
>
> after the relevant promote rule has been created, e.g. by
>
> using Nemo
> R, x = PolynomialRing(ZZ, "x")
> S, y = PolynomialRing(R, "y")
>
> one of the side-effects of which is to create the relevant promote_rule, 
> the function returns false.
>
> However, if I create the promote_rule_exists function in the REPL and call 
> it instead, it returns true.
>
> I have no idea why it would return a different value depending whether it 
> is inside a module or not.
>
> Any ideas?
>
> Bill.
>
>
>
> On Tuesday, 22 March 2016 20:03:49 UTC+1, Jeffrey Sarnoff wrote:
>>
>> This checks whether a specific promote rule  exists:
>>
>> promotionExists{T1, T2}( ::Type{T1}, ::Type{T2} ) =  (Union{} != 
>> promote_rule(T1,T2))
>>
>>
>>
>> On Tuesday, March 22, 2016 at 11:37:56 AM UTC-4, Bill Hart wrote:
>>>
>>> I'm having trouble understanding the following behaviour 
>>> in 0.5.0-dev+3171. I wonder if someone can tell me what I'm doing wrong.
>>>
>>> module Mymod
>>>    type mytype
>>>    end
>>> end
>>>
>>> sig_table = [x.sig for x in methods(Base.promote_rule)]
>>>
>>> V = Tuple{typeof(Base.promote_rule),Type{Mymod.mytype},Type{Int64}}
>>>
>>> V in sig_table # returns true!!
>>>
>>> for s in sig_table # prints yes
>>>    if V == s
>>>       println("yes")
>>>    end
>>> end
>>>
>>> for s in sig_table # prints nothing
>>>    if s == V
>>>       println("yes")
>>>    end
>>> end
>>>
>>> Can someone explain what the difference between == and "in" is. For 
>>> example, why shouldn't == be symmetric? And why should "in" tell me 
>>> something is in an array that is clearly not in there?
>>>
>>> Metaquestion: what is the easiest way of checking if a promote_rule 
>>> already exists? We have to create promote_rules at run time in response to 
>>> user input (so it can't be done statically) and now the Julia compiler 
>>> complains with pages of warnings because we are overwriting existing 
>>> promote rules (actually, we are, harmlessly). We want to get rid of the 
>>> warnings and the easiest way is to check if that promote rule already 
>>> exists before defining it again.
>>>
>>> We can't just do method_exists because it always returns true for 
>>> promote_rule, with any signature. So we need to check whether the promote 
>>> rule with the precise signature we want to define already exists. For 
>>> example
>>>
>>> method_exists(Base.promote_rule, Tuple{Type{Mymod.mytype}, Type{Int}})
>>>
>>> returns true.
>>>
>>> Bill.
>>>
>>

Reply via email to