-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
Consider the following program:
use derive_more::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign};
use noether::{
AssociativeAddition, AssociativeMultiplication, CommutativeAddition, CommutativeMultiplication,
Distributive, PrincipalIdealDomain,
};
use num_traits::{One, Zero};
use std::ops::Neg;
// create and implement the ring ZZ x ZZ
#[derive(Debug, PartialEq, Add, AddAssign, Sub, SubAssign, Mul, MulAssign)]
#[mul(forward)]
#[mul_assign(forward)]
struct ZxZ(isize, isize);
impl AssociativeAddition for ZxZ {}
impl CommutativeAddition for ZxZ {}
impl AssociativeMultiplication for ZxZ {}
impl CommutativeMultiplication for ZxZ {}
impl Distributive for ZxZ {}
impl One for ZxZ {
fn one() -> Self {
ZxZ(1, 1)
}
}
impl Zero for ZxZ {
fn zero() -> Self {
ZxZ(0, 0)
}
fn is_zero(&self) -> bool {
self == &Self::zero()
}
}
impl Neg for ZxZ {
type Output = Self;
fn neg(self) -> Self::Output {
ZxZ(-self.0, -self.1)
}
}
// a function which only accepts an input of a type implementing PrincipalIdealDomain
fn is_pid<T: PrincipalIdealDomain>(_: T) {
println!("My type implements PrincipalIdealDomain.")
}
// mainline shows that ZZ x ZZ implements PrincipalIdealDomain
fn main() {
let pair = ZxZ(5, -3);
is_pid(pair);
}Behaviour
This program compiles and runs without error, printing My type implements PrincipalIdealDomain..
Expected behaviour
I think the code should fail to compile because the explicitly implemented traits should not cause PrincipalIdealDomain to be implemented for ZxZ.
Note
The struct ZxZ represents the commutative ring
Proposal
Remove the following blanket implementations of IntegralDomain, UniqueFactorizationDomain and PrincipalIdealDomain for all types implementing CommutativeRing:
Lines 107 to 109 in 677edcb
| impl<T: CommutativeRing> IntegralDomain for T {} | |
| impl<T: IntegralDomain> UniqueFactorizationDomain for T {} | |
| impl<T: UniqueFactorizationDomain> PrincipalIdealDomain for T {} |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels