Avatar
これで行こうと思います! protocol Ring {} protocol MatrixImpl { associatedtype BaseRing: Ring } struct SomeRing: Ring {} struct Matrix<Impl: MatrixImpl> { init(_ impl: Impl) {} } struct DenseMatrixImpl<A: Ring>: MatrixImpl { typealias BaseRing = A } struct SparseMatrixImpl<A: Ring>: MatrixImpl { typealias BaseRing = A } extension Matrix { func toSparse<A: Ring>() -> Matrix<SparseMatrixImpl<A>> where Impl == DenseMatrixImpl<A> { .init(SparseMatrixImpl<A>()) } func toDense<A: Ring>() -> Matrix<DenseMatrixImpl<A>> where Impl == SparseMatrixImpl<A> { .init(DenseMatrixImpl<A>()) } }
👀 1
🙂 1