@breandan today I had a very brief discussion with Breslav and @elizarov about type-safe matrix dimensions. They think that it could make sense for some tasks, so I will probably will give another try to your idea. Currently 2D-strucutres are thin inline wrappers around ND-structures, so it should be quite easy to add another inline wrapper with type-based dimensions without breaking anything. I will create a prototype based on your ideas and we can discuss it after that.
2 years ago
Cool! If you're looking for ideas, singleton types with dimension encoded in the name is one way: https://github.com/breandan/kotlingrad/blob/master/src/main/kotlin/edu/umontreal/kotlingrad/samples/ToyMatrixExample.kt#L186-L204
For array literals, you can use function arity to disambiguate: https://github.com/breandan/kotlingrad/blob/master/src/main/kotlin/edu/umontreal/kotlingrad/samples/ToyVectorExample.kt#L212-L220
Otherwise, you can always fall back to runtime shape checking for dynamically sized collections: https://github.com/breandan/kotlingrad/blob/d13a0b057f7adfc9b35b5618b2ba25247aaa85a0/src/main/kotlin/edu/umontreal/kotlingrad/dependent/Vec.kt#L6