Nemo - Error in overloading operator '=='

Hello everybody !
I want to construct product rings (fields) of modular integers. For example Z/5ZxZ/7Z
I began like this :

#http://nemocas.github.io/Nemo.jl/v0.6/types/#the-abstract-type-hierarchy-in-nemo
using Nemo
R5 = ResidueRing( ZZ , 5)
R7= ResidueRing( ZZ , 7)
struct Z_sur_5ZxZ_sur_7Z <:RingElem
    c::Tuple{nmod, nmod}
end
const Z57=Z_sur_5ZxZ_sur_7Z #alias
Base.show(io::IO, C::Z57) = print(io,C.c)
couple(x::Int64,y::Int64)=Z57((R5(x),R7(y)))
println(couple(12,13))
zero(Z57)=couple(0,0) #neutre de l'addition
println(zero(Z57))
println(couple(5,7))
one(Z57)=couple(1,1)
println(one(Z57))
Base.:==(C1::Z57,C2::Z57)=(C1.c[1]==C2.c[1])&&(C1.c[2]==C2.c[2])

Everything is OK till the last instruction which gives me the error :

RROR: LoadError: syntax: type declarations on global variables are not yet supported
Stacktrace:
 [1] top-level scope
   @ ~/PycharmProjects/Nemo/src/Anneaux/RingProduct.jl:17
in expression starting at /home/gilles/PycharmProjects/Nemo/src/Anneaux/RingProduct.jl:17

If there’s no attempt to overload, for example with this code :

equality(C1::Z57,C2::Z57)=C1.c==C2.c
println(equality(couple(5,7),zero(Z57))) 

Everything is OK, so the ‘global variable’ reference has nothing to do with the Z57 alias.
Somebody can explain ?
Thank you !
Gilles

You need parantheses around ==, i.e. the last line needs to be:

Base.:(==)(C1::Z57,C2::Z57)=(C1.c[1]==C2.c[1])&&(C1.c[2]==C2.c[2])

Interestingly, Base.:==(C1::Z57,C2::Z57) is parsed as Base.(:=) = (C1::Z57,C2::Z57), which is quite surprising and could arguably be considered a parser bug.

2 Likes

Thank you so much Simeon. It works !!

Base.:(==)(C1::Z57,C2::Z57)=C1.c==C2.c
println(zero(Z57)==couple(5,7))
Base.:+(C1::Z57,C2::Z57)=Z57((C1.c[1]+C2.c[1],C1.c[2]+C2.c[2]))
println(zero(Z57)+one(Z57))

I began to have doubts about the symbol ‘==’ because in the meantime I overloaded other binary operators like + without any problem.
By the way strict equality of couples is directly understood which allows a little simpler form.
I consider this question solved.
Best regards.
Gilles