diff options
Diffstat (limited to 'notes/easy_linear_types.txt')
-rw-r--r-- | notes/easy_linear_types.txt | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/notes/easy_linear_types.txt b/notes/easy_linear_types.txt new file mode 100644 index 0000000..8c60122 --- /dev/null +++ b/notes/easy_linear_types.txt @@ -0,0 +1,62 @@ +Easy-to-use linear types +======================== + +Allow simple usage of linear types when using only local variables +and/or parameters and/or return values. + +Have a "lock system" with automatic garbage collection (collected no later +than when the arena is destroyed) for more complex cases. + + +Assume that `open` create a linear/owned `File` type. + +Trivial case: + + func stuff + code + own File f = open "file.txt" .write + write f "hello" # uses `f` but does not take ownership + close f # takes ownership of `f` + end + +Nested case: + + func get_file + returns + own File f + code + # Allow simple usage when returning + return open "file.txt" .write + end + +Complex case: + + func maybe_open_file + code + if use_file + # + begin_ownership thefile + thefile = open "file.txt" .write + suspend_ownership thefile + # disallow changing the `file` variable when it is + # suspended? + end + end + + func maybe_write_to_file + code + if use_file + resume_ownership file + write thefile "hello" + suspend_ownership file + end + end + + func maybe_close_file + code + if use_file + resume_ownership thefile + close thefile + end_ownership thefile + end + end |