4 ms·
You can build safe abstractions for manual memory management in userspace with LinearTypes. In fact Haskell already has plenty of manual memory management modul
by whateveracct 6y ago
You can build safe abstractions for manual memory management in userspace with LinearTypes. In fact Haskell already has plenty of manual memory management modules in its stdlib - it's just that they live in IO.
You can do the unsafePerformIO internally and expose a pure API made safe by some combination of LinearTypes and the ST trick.
- cryptonector 6y agoTo use linear types for everything will require new libraries, no?
- whateveracct 6y agoDepends in your definition of "everything" If you want to manually manage all memory, then yes you'll have to not use `base` and any pure functional data structure. There's been a lot of "this feature is going to ruin the ecosystem" FUD but it's not much more that that imo
- xvilka 6y agoThere is `linear-base`[1] for this. [1] https://github.com/tweag/linear-base https://github.com/tweag/linear-base
- cryptonector 6y agoI wasn't suggesting this would "ruin the ecosystem". Rather, I was suggesting we might end up with two ecosystems.
- Tarean 6y agoLinearTypes guarantee that all values are used exactly once if the result is used exactly once. If an exception is thrown, the result won't be used once and the memory would leak. One cheap way is to also track the memory with the GC. This is similar to using GC finalizers on file handles - closing handles via GC is inefficient and slow but it's only the last resort. Another option is to use exception handlers to guarantee that the Ressource is freed. Either one handler per Ressource which destroys all advantages of linear types, or one handler in total and some mutable memory to track the still open resources.