Skip to content

Commit

Permalink
Make is_exact_type and is_domain_type more convenient
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fingolfin committed Dec 20, 2024
1 parent 9843ed5 commit 28b0cb3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,28 @@ end

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

# Type can only represent elements of domains
is_exact_type(x) = is_exact_type(typeof(x))
is_exact_type(x::Type{<:Ring}) = is_exact_type(elem_type(x))
is_exact_type(T::DataType) = throw(MethodError(is_exact_type, (T,)))

Check warning on line 106 in src/Rings.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings.jl#L104-L106

Added lines #L104 - L106 were not covered by tests

# Type can only represent elements of domains, i.e. without zero divisors
# false unless explicitly specified
#
# implementors should only implement this trait for RingElem subtypes, but for
# convenience we support calling this also on Ring subtypes as well as Ring
# and RingElem instances
is_domain_type(R::Type{T}) where T <: RingElem = false

is_domain_type(x) = is_domain_type(typeof(x))
is_domain_type(x::Type{<:Ring}) = is_domain_type(elem_type(x))
is_domain_type(T::DataType) = throw(MethodError(is_domain_type, (T,)))

Check warning on line 118 in src/Rings.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings.jl#L116-L118

Added lines #L116 - L118 were not covered by tests

###############################################################################
#
# Exponential function for generic rings
Expand Down

0 comments on commit 28b0cb3

Please sign in to comment.