Определение AdditiveGroup с помощью ящика для водорослей - PullRequest
0 голосов
/ 22 января 2019

Согласно документации водоросли , макросы (определенные в alga_traits):

#[derive(Alga)]
#[alga_traits(Group(Additive))]
struct TrivialGroup;

могут использоваться для реализации признака маркера AbstractGroup с оператором Additive, еслипредусмотрены реализации признаков Identity, PartialEq, Inverse и AbstractMagma.

Однако, если я реализую их как:

use alga::general::{AbstractMagma, Additive, AdditiveGroup, Identity, Inverse}; // 0.7.2
use alga_derive::Alga; // 0.7.1

#[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 {}
    }
}

struct Bar<T: AdditiveGroup> {
    t: T,
}

fn main() {
    let foo = Bar::<TrivialGroup> { t: TrivialGroup {} };
}

Компилятор все еще не 'Не думаю, что TrivialGroup удовлетворяет черте AdditiveGroup:

error[E0277]: the trait bound `TrivialGroup: num_traits::identities::Zero` is not satisfied
  --> src/main.rs:31:15
   |
31 |     let foo = Bar::<TrivialGroup> { t: TrivialGroup {} };
   |               ^^^^^^^^^^^^^^^^^^^ the trait `num_traits::identities::Zero` is not implemented for `TrivialGroup`
   |
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveLoop` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
  --> src/main.rs:26:1
   |
26 | struct Bar<T: AdditiveGroup> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `TrivialGroup: std::ops::Neg` is not satisfied
  --> src/main.rs:31:15
   |
31 |     let foo = Bar::<TrivialGroup> { t: TrivialGroup {} };
   |               ^^^^^^^^^^^^^^^^^^^ the trait `std::ops::Neg` is not implemented for `TrivialGroup`
   |
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::ClosedNeg` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveLoop` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
  --> src/main.rs:26:1
   |
26 | struct Bar<T: AdditiveGroup> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: cannot subtract `TrivialGroup` from `TrivialGroup`
  --> src/main.rs:31:15
   |
31 |     let foo = Bar::<TrivialGroup> { t: TrivialGroup {} };
   |               ^^^^^^^^^^^^^^^^^^^ no implementation for `TrivialGroup - TrivialGroup`
   |
   = help: the trait `std::ops::Sub` is not implemented for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::ClosedSub` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveQuasigroup` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveLoop` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
  --> src/main.rs:26:1
   |
26 | struct Bar<T: AdditiveGroup> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: cannot subtract-assign `TrivialGroup` from `TrivialGroup`
  --> src/main.rs:31:15
   |
31 |     let foo = Bar::<TrivialGroup> { t: TrivialGroup {} };
   |               ^^^^^^^^^^^^^^^^^^^ no implementation for `TrivialGroup -= TrivialGroup`
   |
   = help: the trait `std::ops::SubAssign` is not implemented for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::ClosedSub` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveQuasigroup` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveLoop` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
  --> src/main.rs:26:1
   |
26 | struct Bar<T: AdditiveGroup> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: cannot add-assign `TrivialGroup` to `TrivialGroup`
  --> src/main.rs:31:15
   |
31 |     let foo = Bar::<TrivialGroup> { t: TrivialGroup {} };
   |               ^^^^^^^^^^^^^^^^^^^ no implementation for `TrivialGroup += TrivialGroup`
   |
   = help: the trait `std::ops::AddAssign` is not implemented for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::ClosedAdd` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveSemigroup` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveMonoid` for `TrivialGroup`
   = note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
  --> src/main.rs:26:1
   |
26 | struct Bar<T: AdditiveGroup> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Как мне вместо этого определить мою аддитивную группу?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...