Skip to content

Make is_exact_type and is_domain_type more convenient #1942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

# 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
Loading