diff --git a/crates/types/src/compound/list.rs b/crates/types/src/compound/list.rs index cc4a72a..1c0fc2d 100644 --- a/crates/types/src/compound/list.rs +++ b/crates/types/src/compound/list.rs @@ -4,28 +4,28 @@ use crate::compound::peano::{P0, Peano, PNext}; struct Null; #[derive(Copy, Clone, Default, PartialEq)] -struct LLNode { - e: E, +struct LLNode { + head: H, // Null or LLNode - next: N, + tail: T, } -impl LLNode { - fn new(e: E, next: N) -> Self { - Self { e, next } +impl LLNode { + fn new(head: H, tail: T) -> Self { + Self { head, tail } } - fn prepend

(self, e: P) -> LLNode { + fn prepend

(self, head: P) -> LLNode { LLNode { - e, - next: self + head, + tail: self, } } } -impl LLNode { - fn new_terminal(e: E) -> Self { - Self::new(e, Null) +impl LLNode { + fn new_terminal(head: H) -> Self { + Self::new(head, Null) } } @@ -105,22 +105,22 @@ impl R> ElementOp for F { } } -impl ListOp, Output> for LLNode +impl ListOp, Output> for LLNode where - F: ElementOp, - N: ListOp + F: ElementOp, + T: ListOp { fn apply_all(&self, f: F) { // apply the operation to our element - f.call(&self.e); + f.call(&self.head); // apply the operation to all tail elements - self.next.apply_all(f); + self.tail.apply_all(f); } fn apply_at_rel(&self, i: u32, cur: u32, f: F) -> Output { if i == cur { - f.call(&self.e) + f.call(&self.head) } else { - self.next.apply_at_rel(i, cur + 1, f) + self.tail.apply_at_rel(i, cur + 1, f) } } } @@ -147,27 +147,27 @@ trait IndexOp { } /// zero-index into Self -impl IndexOp, P0, E> for LLNode +impl IndexOp, P0, H> for LLNode { - fn get(&self, _idx: P0) -> &E { - &self.e + fn get(&self, _idx: P0) -> &H { + &self.head } - fn get_mut(&mut self, _idx: P0) -> &mut E { - &mut self.e + fn get_mut(&mut self, _idx: P0) -> &mut H { + &mut self.head } } /// index N+1 into Self given that we know how to index N into Self::next -impl IndexOp, PNext

, ElemAtP> for LLNode +impl IndexOp, PNext

, ElemAtP> for LLNode where P: Peano, - N: IndexOp + T: IndexOp { fn get(&self, _idx: PNext

) -> &ElemAtP { - self.next.get(P::default()) + self.tail.get(P::default()) } fn get_mut(&mut self, _idx: PNext

) -> &mut ElemAtP { - self.next.get_mut(P::default()) + self.tail.get_mut(P::default()) } }