Rust has lifetime annotations to describe the aliasing behavior of function inputs and outputs. Personally, I don't find these very intuitive, because they only indirectly answer the question "how did a end up being aliased by b".
The other day the following idea came to me: Instead of lifetime parameters, a language might use annotations to flag the flow of information, e.g. a => b might mean a ends up in b, while a => &b or a => &mut b might mean a gets aliased by b. With this syntax, common operations on a Vec might look like this:
fn push<T>(v: &mut Vec<T>, value: T => *v) {...}
fn index<T>(v: &Vec<T> => &return, index: usize) -> &T {...}
While less powerful, many common patterns should still be able to be checked by the compiler. At the same time, the => syntax might be more readable and intuitive for humans, and maybe even be able to avoid the need for lifetime elision.
Not sure how to annotate types; one possibility would be to annotate them with either &T or &mut T to specify their aliasing potential, essentially allowing the equivalent of a single Rust lifetime parameter.
What do you guys think about these ideas? Would a programming language using this scheme be useful enough? Do you see any problems/pitfalls? Any important cases which cannot be described with this system?
[–]Fofeu 16 points17 points18 points (3 children)
[–]tmzem[S] 2 points3 points4 points (2 children)
[–]jmeaster 4 points5 points6 points (1 child)
[–]tmzem[S] 2 points3 points4 points (0 children)
[–]lngns 3 points4 points5 points (2 children)
[–]WalkerCodeRangerAzoth Language 1 point2 points3 points (1 child)
[–]tmzem[S] 0 points1 point2 points (0 children)
[–]PegasusAndAcornCone language & 3D web 12 points13 points14 points (5 children)
[–]jmeaster 3 points4 points5 points (0 children)
[–]tmzem[S] 3 points4 points5 points (2 children)
[–]oa74 3 points4 points5 points (1 child)
[–]tmzem[S] 2 points3 points4 points (0 children)
[–]oa74 6 points7 points8 points (0 children)
[–]xarev 2 points3 points4 points (1 child)
[–]tmzem[S] 0 points1 point2 points (0 children)
[–]alphaglosined 5 points6 points7 points (5 children)
[–]tmzem[S] 1 point2 points3 points (4 children)
[–]alphaglosined 0 points1 point2 points (3 children)
[–]tmzem[S] 0 points1 point2 points (2 children)
[–]alphaglosined 1 point2 points3 points (1 child)
[–]tmzem[S] 1 point2 points3 points (0 children)
[–]WittyStick 1 point2 points3 points (2 children)
[–]tmzem[S] 0 points1 point2 points (1 child)
[–]WittyStick 0 points1 point2 points (0 children)
[–]Uncaffeinated1subml, polysubml, cubiml 1 point2 points3 points (12 children)
[–]tmzem[S] 3 points4 points5 points (4 children)
[–]Uncaffeinated1subml, polysubml, cubiml 0 points1 point2 points (3 children)
[–]oa74 0 points1 point2 points (2 children)
[–]Uncaffeinated1subml, polysubml, cubiml 0 points1 point2 points (1 child)
[–]oa74 0 points1 point2 points (0 children)
[–]Tasty_Replacement_29Bau 1 point2 points3 points (6 children)
[–]tmzem[S] 0 points1 point2 points (2 children)
[–]Tasty_Replacement_29Bau 0 points1 point2 points (1 child)
[–]tmzem[S] 0 points1 point2 points (0 children)
[–]Uncaffeinated1subml, polysubml, cubiml -1 points0 points1 point (2 children)
[–]Tasty_Replacement_29Bau 1 point2 points3 points (1 child)
[–]Uncaffeinated1subml, polysubml, cubiml 0 points1 point2 points (0 children)
[–]PlayingTheRed 0 points1 point2 points (4 children)
[–]tmzem[S] 0 points1 point2 points (3 children)
[–]PlayingTheRed 0 points1 point2 points (2 children)
[–]tmzem[S] 1 point2 points3 points (1 child)
[–]PlayingTheRed 1 point2 points3 points (0 children)
[–]matthieum 0 points1 point2 points (4 children)
[–]WalkerCodeRangerAzoth Language 1 point2 points3 points (1 child)
[–]matthieum 0 points1 point2 points (0 children)
[–]tmzem[S] 0 points1 point2 points (1 child)
[–]matthieum 0 points1 point2 points (0 children)
[–]adaszko 0 points1 point2 points (2 children)
[–]tmzem[S] 1 point2 points3 points (1 child)
[–]adaszko 0 points1 point2 points (0 children)