     }
     
     mutating func apply(_ s: EliminationStep<R>) {
-        s.applyTo(&result)
+        result.apply(s)
         process.append(s)
     }
     

    fileprivate override var result: (matrix: Matrix<R, n, m>, process: [EliminationStep<R>]) {
        fatalError("not yet impled.")
    }
}

private enum EliminationStep<R: Ring> {
    case AddRow(at: Int, to: Int, mul: R)
    case InvRow(Int)
    case SwapRows(Int, Int)
    case AddCol(at: Int, to: Int, mul: R)
    case InvCol(Int)
    case SwapCols(Int, Int)
    
    func applyTo<n: _Int, m: _Int>(_ A: inout Matrix<R, n, m>) {
        switch self {
        case let .AddRow(i, j, r):
            A.addRow(at: i, to: j, multipliedBy: r)
        case let .InvRow(i):
            A.multiplyRow(at: i, by: -1)
        case let .SwapRows(i, j):
            A.swapRows(i, j)
        case let .AddCol(i, j, r):
            A.addCol(at: i, to: j, multipliedBy: r)
        case let .InvCol(i):
            A.multiplyCol(at: i, by: -1)
        case let .SwapCols(i, j):
            A.swapCols(i, j)
        }
    }
    
    func applyInverseTo<n: _Int, m: _Int>(_ A: inout Matrix<R, n, m>) {
        switch self {
        case let .AddRow(i, j, r):
            A.addRow(at: i, to: j, multipliedBy: -r)
        case let .AddCol(i, j, r):
            A.addCol(at: i, to: j, multipliedBy: -r)
        case _:
            applyTo(&A)
        }
    }
}

            // TODO maybe implement NumberType or Comparable
            if R.self == IntegerNumber.self && (result[i0, j0] as! IntegerNumber) < 0 {
                if doRows {
                    self.apply(.MulRow(at: i0, by: -1))
                } else {
                    self.apply(.MulCol(at: j0, by: -1))
                }
            }
            
