Re:Announcing Rust 1.28
by lmm on Thursday August 02, 2018 @01:28PM
(#17673455)
Does "const generics" essentially mean singleton types?
[ Parent
| on HN ]
Re:Announcing Rust 1.28
by steveklabnik on Thursday August 02, 2018 @01:36PM
(#17673523)
There are so many "slightly different but mostly the same" things in this space. In Rust, this is const generics: https://github.com/rust-lang/rfcs/blob/master/text/2000-cons...
struct RectangularArray<T, const WIDTH: usize, const HEIGHT: usize> {
array: [[T; WIDTH]; HEIGHT],
}
const X: usize = 7;
fn main() {
let x: RectangularArray<i32, 2, 4>;
let y: RectangularArray<i32, X, {2 * 2}>;
}
I haven't read enough about singleton types to know the exact details about their similarities, so I'm not sure.
Re:Announcing Rust 1.28
by lordnaikon on Thursday August 02, 2018 @06:37PM
(#17676053)
Is this what is known as pi or dependent types?
Yes, but limited to being applied at compile-time, with constant arguments.
Fully general dependent type would allow passing in runtime values, which is significantly harder to type-check and execute
Re:Announcing Rust 1.28
by steveklabnik on Thursday August 02, 2018 @07:26PM
(#17676289)
I believe that this initial version is not quite fully pi types; we did have an RFC for those but it was deemed too large to start off with.