From 26a0fe589b0140917d7459e135ca79513cf0bace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 1 Apr 2021 10:27:37 +0200 Subject: [PATCH] operate on one and zero pass value not type --- src/interface.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index fa73e97d..9e5efbeb 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -113,10 +113,12 @@ operate(::typeof(convert), ::Type{T}, x::T) where {T} = copy_if_mutable(x) operate(::Union{typeof(+),typeof(*)}, x) = copy_if_mutable(x) -# We only give the type to `zero` and `one` to be sure that modifying the -# returned object cannot alter `x`. -operate(::typeof(zero), x) = zero(typeof(x)) -operate(::typeof(one), x) = one(typeof(x)) +# We could only give `typeof(x)` to `zero` and `one` to be sure that modifying the +# returned object cannot alter `x` but for some objects, `one` and `zero` depends +# on some values of the fields (e.g. square matrices), elements of the cyclic group +# of order `n` (`n` is one of the field). +operate(::typeof(zero), x) = zero(x) +operate(::typeof(one), x) = one(x) # Define Traits