# Nemo - Error in overloading operator '=='

**URL:** <https://discourse.julialang.org/t/nemo-error-in-overloading-operator/67773>\
**Category:** General Usage\
**Tags:** nemo\
**Created:** [September 6, 2021, 8:34pm UTC](https://discourse.julialang.org/t/nemo-error-in-overloading-operator/67773 "2021-09-06T20:34:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gilles\_Dubois](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gilles_dubois/32/25830_2.png) [@Gilles\_Dubois](https://discourse.julialang.org/u/Gilles_Dubois)\
**Post date:** [September 6, 2021, 8:34pm UTC](https://discourse.julialang.org/t/nemo-error-in-overloading-operator/67773/1 "2021-09-06T20:34:06Z")

</div>

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

```julia
#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 :

```julia
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 :

```julia
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

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [September 6, 2021, 9:04pm UTC](https://discourse.julialang.org/t/nemo-error-in-overloading-operator/67773/2 "2021-09-06T21:04:00Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![Gilles\_Dubois](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gilles_dubois/32/25830_2.png) [@Gilles\_Dubois](https://discourse.julialang.org/u/Gilles_Dubois)\
**Post date:** [September 6, 2021, 9:17pm UTC](https://discourse.julialang.org/t/nemo-error-in-overloading-operator/67773/3 "2021-09-06T21:17:13Z")

</div>

Thank you so much Simeon. It works !!

```julia
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
