3 ms·
Function programming with no garbage collector is tough. There is a formalisation for dealing with this, called linear logic, which allows you to statically det
by david-given 10y ago
Function programming with no garbage collector is tough. There is a formalisation for dealing with this, called linear logic, which allows you to statically determine object lifetimes; but it's, um, a bit awkward. Such as, every value must be produced once and consumed once, so if you want to look at a variable, you need to produce a new variable with the same value (which must be consumed later).
The seminal linearly typed language is Linear Lisp, which is almost incomprehensible, and also a proof-of-concept which doesn't do anything useful. Classic paper here:
http://home.pipeline.com/~hbaker1/LinearLisp.html http://home.pipeline.com/~hbaker1/LinearLisp.html
The closest thing to a modern language that uses them exclusively (Rust doesn't, by the way) is LinearML, which was an experimental toy, now abandoned. Tutorial here, which may be interesting:
https://github.com/pikatchu/LinearML/wiki/Tutorial https://github.com/pikatchu/LinearML/wiki/Tutorial
I asked about it on StackOverflow a while back, and it collected a bunch of useful resources, including links to some of the seminal papers:
http://stackoverflow.com/questions/5065861/programming-languages-based-on-linear-types http://stackoverflow.com/questions/5065861/programming-langu...
(Still looking for a modern pure linear typed language, by the way.)
- tupshin 10y agoIn what way is Rust's use of affine lifetimes insufficient to implement "function programming with no garbage collection"? Genuine question, given my previous interest :) https://twitter.com/tupshin/status/587275945163251713 https://twitter.com/tupshin/status/587275945163251713 https://twitter.com/tupshin/status/626164932778819584 https://twitter.com/tupshin/status/626164932778819584
- david-given 10y agoIn Rust you're allowed to look at values without consuming them, which pure linear typing doesn't support (it requires exactly one producer and exactly one consumer). Also, in my experience, most Rust programs tend to stash stuff in reference-counted boxes whenever calculating lifetime gets complex; which is reasonable enough (C++ does the same thing), but it is basically garbage collection, and I'd like to find an expressive, functional, non-GCd language which doesn't require this.
- agumonkey 10y agoH.Baker text on linear (lisp) was yet another mind bending piece from him. Greatly recommended.