Idea: Describing dynamicly sized types using const generics

For some reason I think this feels wrong. I think, mostly, it's because I don't think it emphasizes that this has a runtime cost. I think I keep wanting fn f(_: for<T: Tr> T); to be a janky APIT. Of course, fn f() -> for<T: Tr> T; makes zero sense for RPIT (for doesn't really yell "existential type" to me...).

[Having mentioned impl Trait I feel vaguely compelled to say something nonsensical like "we should add fn foo() -> impl<const N: usize> [T; impl]", for when you really want to hide the returned const's value...]

1 Like

These things would still be sort of doable in your proposed syntax:

type DualView<'a, const N: usize> = (&'a [T; N], &'a [T; N]);
DualView<dyn usize> = dyn<const N: usize> (&[T; N], &[T; N])
(&[T; dyn usize], &[T; dyn usize]) = (&dyn<const N: usize> [T;N], &dyn<const N: usize>)

I see this as very problematic consequence, as type is supposed to be an alias, and as such should not change behaviour.

This seems very reasonable to me. If dyn Trait is just a special case that desugers to dyn<T: Trait> T. Then it would be natural to do the same thing with impl.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.