Open jeremysalwen opened 5 years ago
There is some confusion here: alga_derive
implements AbstractGroup<Additive>
for you which is different from AdditiveGroup
which requires the extra Zero
, Neg
, SubAssign
, AddAssign
traits to be implemented.
These restrict to what kind of things it can accept, but as a trade make using it cleaner
The alga_derive
documentations doesn't talk about this explicitly though.
I think I understand, but are you sure that list of required traits is complete? The compiler is complaining, I think it wants me to implement Add
as well. So it seems like in total, in order to define an AdditiveGroup
I need all this boilerplate?
#[derive(Alga, Clone, Copy, PartialEq, Debug)]
#[alga_traits(Group(Additive))]
pub struct TrivialGroup;
impl AbstractMagma<Additive> for TrivialGroup {
fn operate(&self, _right: &Self) -> Self {
TrivialGroup {}
}
}
impl Identity<Additive> for TrivialGroup {
fn identity() -> Self {
TrivialGroup {}
}
}
impl Inverse<Additive> for TrivialGroup {
fn inverse(&self) -> Self {
TrivialGroup {}
}
}
impl Zero for TrivialGroup {
fn zero() -> Self {
TrivialGroup::identity()
}
fn is_zero(&self) -> bool {
true
}
}
impl Add for TrivialGroup {
type Output = TrivialGroup;
fn add(self, _other: TrivialGroup) -> Self::Output {
self
}
}
impl Neg for TrivialGroup {
type Output = TrivialGroup;
fn neg(self) -> TrivialGroup {
self
}
}
impl AddAssign for TrivialGroup {
fn add_assign(&mut self, _other : TrivialGroup) {
}
}
impl SubAssign for TrivialGroup {
fn sub_assign(&mut self, _other :TrivialGroup) {
}
}
It seems like there are only three things I'm defining: the "add" operator, the "negate" operator, and the "zero" element, but I still have to manually implement 8 Traits on top of everything that alga_derive derives? Is there really no macro that does the obvious derivations of the 5 redundant traits?
@jeremysalwen That's correct. We only have macros for implementing the Abstract*
traits currently. Though adding macros for the non-Abstract traits would definitely be a great addition.
If I define an additive group according to the instructions in the documentation, it still will not satisfy the AdditiveGroup trait, and I can't do addition with it (e.g.
element + element
).Gives the error:
See also: https://stackoverflow.com/questions/54303935/defining-additivegroup-with-alga-crate