In Nemo.jl we require some objects to be singleton. In other words they should never be deep copied since we require only one of them to exist.
This is causing a problem with deepcopy of arrays that somewhere contain these objects. E.g. in Nemo.jl: Qx,x = PolynomialRing(QQ, "x") # here x contains one of these "singleton" objects A = [x] deepcopy(A)[1] == x deepcopy(A)[1] == x ERROR: Incompatible polynomial rings in polynomial operation [inlined code] from /home/wbhart/.julia/v0.5/Nemo/src/generic/Poly.jl:33 in == at /home/wbhart/.julia/v0.5/Nemo/src/flint/fmpq_poly.jl:281 in eval at ./boot.jl:263 The error message is one Nemo itself raises, and it is of course because deepcopy(A) does a deep copy of everything in the array, including x, and that causes a deepcopy of the singleton object inside x. I thought simply overriding the deepcopy method for our singleton objects would do the trick: Base.deepcopy(R::Nemo.Ring) = R but this doesn't fix the issue. So what is the recommended way to have this recursive deepcopy of arrays not make a copy of anything of type T <: Nemo.Ring? It seems I can overload deepcopy_internal, but this seems like an unsupported hack. Is there something more canonical I should be doing to handle singleton objects? Bill. P.S: Yes, I realise copy(A) does not have this problem. But I am specifically asking about the situation where we want to deepcopy an array.
