logoalt Hacker News

veber-alextoday at 4:08 PM4 repliesview on HN

It's impossible to add a borrow checker to any existing language.

The reason Rust has a working borrow checker is because every part of the language from structs, enum, traits, generics and all the way to the syntax itself has been designed to support lifetimes and borrow checking.

It's is not something you can just tack on to an existing language without fundamentally changing it.


Replies

solatictoday at 4:19 PM

I wouldn't say it's impossible, rather un-ergonomic. TypeScript can add type information to ordinary JavaScript code via JSDoc comments; the result can both be executed as ordinary JavaScript as-is and type-checked with TypeScript. But it's a huge pain to try to write (and maintain) everything that way, it was supported as a hack to help migrate legacy codebases. You could probably take a similar "the lifetimes are embedded in comments" approach with other languages, and the result would be similarly un-ergonomic.

show 1 reply
kfusetoday at 5:26 PM

C# was already a very mature language when it had referenes and later "ref safety" added to it.

pjmlptoday at 4:54 PM

Swift, Linear Haskell, Chapel, Ada/SPARK are all counter examples from such claim.

show 1 reply
dnauticstoday at 4:43 PM

> It's impossible to add a borrow checker to any existing language.

Why do you say that. Have you tried and failed? It seems to be possible to add a borrow checker to zig, just as you can add MIRI to rust to get extra safety in unsafe blocks.