Skip to content

Commit 4ae9859

Browse files
authored
Make is_exact_type and is_domain_type more convenient (#1942)
For examples, this now works: julia> is_domain_type(ZZ) true julia> is_domain_type(ZZ(2)) true julia> is_domain_type(residue_ring(ZZ,6)[1]) false
1 parent 9843ed5 commit 4ae9859

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Rings.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,28 @@ end
9595

9696
# Type can only represent elements of an exact ring
9797
# true unless explicitly specified
98+
#
99+
# implementors should only implement this trait for RingElem subtypes, but for
100+
# convenience we support calling this also on Ring subtypes as well as Ring
101+
# and RingElem instances
98102
is_exact_type(R::Type{T}) where T <: RingElem = true
99103

100-
# Type can only represent elements of domains
104+
is_exact_type(x) = is_exact_type(typeof(x))
105+
is_exact_type(x::Type{<:Ring}) = is_exact_type(elem_type(x))
106+
is_exact_type(T::DataType) = throw(MethodError(is_exact_type, (T,)))
107+
108+
# Type can only represent elements of domains, i.e. without zero divisors
101109
# false unless explicitly specified
110+
#
111+
# implementors should only implement this trait for RingElem subtypes, but for
112+
# convenience we support calling this also on Ring subtypes as well as Ring
113+
# and RingElem instances
102114
is_domain_type(R::Type{T}) where T <: RingElem = false
103115

116+
is_domain_type(x) = is_domain_type(typeof(x))
117+
is_domain_type(x::Type{<:Ring}) = is_domain_type(elem_type(x))
118+
is_domain_type(T::DataType) = throw(MethodError(is_domain_type, (T,)))
119+
104120
###############################################################################
105121
#
106122
# Exponential function for generic rings

0 commit comments

Comments
 (0)