Remix.run Logo
VorpalWay 5 hours ago

You can do this with templates in C++ and generics in Rust I'm pretty sure. I think the Eigen C++ library supports this. (I have yet to do a linear algebra heavy Rust project, so I can't speak to the options that exist there.)

ethanlipson 4 hours ago | parent | next [-]

I'm talking about cases where the array size is not known at compile time. For example, say the user passes in a list of numbers as command line arguments. Then we have

  argv: Vec<String, argc>
If I want to map these to ints, then I'd like a compile-time guarantee that the resulting array

  nums: Vec<Int, argc>
is the same length as argv. Lean and Idris can do this, but AFAIK no commonly used languages can. But unlike general dependent types, these are not hard to wrap one's head around and would save a lot of frustration, in my experience.
otabdeveloper4 5 hours ago | parent | prev [-]

Yeah, C++ arrays are literally that.

alpinisme 5 hours ago | parent | next [-]

Arrays are not dynamically sized though (handling runtime sizes) and don’t have efficient append/concat. The point of the dependent types is that you can have the type system track that concat creates an M+N length vector, sort preserves length (and adds a sorted guarantee that slice preserves), etc. Sure you can do a lot with templates, but that’s advanced templates not just “C++ arrays” in a throwaway “literally that” way.

5 hours ago | parent | prev [-]
[deleted]