use std::ops::Add; pub enum Sum where Con: IsConType, Rhs: IsRepType { Left(Con), Right(Rhs), } pub struct Product where Rhs: IsConType { pub left: T, pub right: Rhs } impl Add> for Product where Rest: Add + IsConType, Field: Add, RestRhs: IsConType, Rest::Output: IsConType { type Output = Product; fn add(self, other: Product) -> Self::Output { Product { left: self.left + other.left, right: self.right + other.right } } } pub struct Field { pub value: T } impl> Add> for Field { type Output=Field; fn add(self, rhs: Field) -> Self::Output { Field { value: self.value + rhs.value, } } } // types used for generic representation pub trait IsRepType {} impl IsRepType for Sum where Lhs: IsConType, Rhs: IsRepType {} impl IsRepType for Product where Rhs: IsConType {} impl IsRepType for Field {} // types that represent constructors pub trait IsConType {} impl IsConType for Product where Rhs: IsConType {} impl IsConType for Field {} pub trait Generic { type Representation: IsRepType; fn generalize(self) -> Self::Representation; fn specialize(rep: Self::Representation) -> Self; }