alantech / alan

Autoscalable Programming Language
https://alan-lang.org
MIT License
305 stars 10 forks source link

Implement the Buffer len function with a type system hat-trick #792

Closed dfellis closed 1 month ago

dfellis commented 1 month ago

If I only cared about the buffer length, this would be a bad PR because it's much large now than before, but now it's possible to use resolved Int or Float types as values within the code. It's unfortunately jumping through a useless function at the moment, but hopefully that can be eliminated in the future.

But in any case, this is particularly useful for any code that needs to use a generic-derived integer or float type as a value to accomplish what's necessary. Here returning the length of a buffer by just inspecting the type information, but it could potentially be used for matrix math or what-have-you, and before it required writing a Rust function to get at this information, and now it's pure Alan code.