     
     private func index(_ i: Int, _ j: Int) -> Int {
         return (i * cols) + j
+    }
+    
+    public subscript(index: Int) -> R {
+        get {
+            return elements[index]
+        }
+        set {
+            elements[index] = newValue
+        }
     }
     
     public subscript(i: Int, j: Int) -> R {

    public init(_ gen: (Int, Int) -> R) {
        let rows = n.value
        let cols = m.value
        let elements = (0 ..< rows * cols).map { gen($0 / rows, $0 % cols) }
        self.init(elements: elements)
    }
    

    
    public static var identity: Matrix<R, n, m> {
        return self.init { $0 == $1 ? 1 : 0 }
    }
}

public typealias ColVector<R: Ring, n: _Int> = Matrix<R, n, _1>
public typealias RowVector<R: Ring, m: _Int> = Matrix<R, _1, m>

public extension Matrix {
    public func rowVector(_ i: Int) -> RowVector<R, m> {
        return RowVector<R, m>{(_, j) -> R in
            return self[i, j]
        }
    }
    
    public func colVector(_ j: Int) -> ColVector<R, n> {
        return ColVector<R, n>{(i, j0) -> R in
            print("\(i), \(j0)")
            return self[i, j0]
        }
    }
}

