number_types/
mul.rs

1use crate::*;
2
3pub trait Mul<Rhs: Number>: Number {
4    type Output: Number;
5}
6
7impl<Rhs: Number> Mul<Rhs> for Zero {
8    type Output = Zero;
9}
10
11// multiplies by repeated addition
12/* (0 + 1) * (0 + 1 + 1)
13Mul<
14    N = Zero,
15    Rhs = Successor<Successor<Zero>>,
16    Output = Rhs + Zero * Rhs,
17>
18*/
19impl<N: Number, Rhs: Number> Mul<Rhs> for Successor<N>
20where
21    N: Mul<Rhs>,
22    Rhs: Add<<N as Mul<Rhs>>::Output>,
23{
24    type Output = <Rhs as Add<<N as Mul<Rhs>>::Output>>::Output;
25}
26
27// multiplication of something negative:
28// -a * b = -(a * b)
29impl<N: Number, Rhs: Number> Mul<Rhs> for Negative<N>
30where
31    N: Mul<Rhs>,
32    <N as Mul<Rhs>>::Output: Neg,
33{
34    type Output = <<N as Mul<Rhs>>::Output as Neg>::Output;
35}
36
37pub trait MulOp {
38    type Output: Number;
39}
40
41impl<Lhs: Number, Rhs: Number> MulOp for Op<Lhs, Rhs>
42where
43    Lhs: Mul<Rhs>,
44{
45    type Output = <Lhs as Mul<Rhs>>::Output;
46}