Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

2 would be a kind of explicit destructors/drop ?


Something like this fictional language,

    with-some-resource { res ->
         // use res as you like
    }

The with-some-resource function takes care of the resource management, while the type system takes care res doesn't escape the lambda.


What if you want to move the ownership of the resource and let the new owner eventually to dispose it?


Then withX isn't the right abstraction.

The original situation (malloc gives you a linear variable) handles what you want. A function that takes the variable but does not return it effectively "takes ownership of it" and the type system will force a free.

There's a "Linear Constraints" paper draft out there that emulates ownership and borrowing with linear types, and uses the titular new language feature to greatly improve ergonomics.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: