4 ms·
This works in Haskell because it is a purely functional language, and the IO monad is an intrusion into that to allow for useful computation. Rust is not purely
by steeleduncan 5y ago
This works in Haskell because it is a purely functional language, and the IO monad is an intrusion into that to allow for useful computation. Rust is not purely functional, so there is no way to enforce something like this in the compiler. You could add an IO monad, but it would be easy for someone further down the chain of packages to ignore it and make a syscall.
Anything similar in rust would have to be enforced through code auditing tools, either forking the compiler, using some of its code as a basis or starting from scratch.
- joshmarlow 5y agoOh you're totally right; I think it would have to be a purely functional framing - I don't think we could shoe-horn this into Rust. I should have prefaced my comment with a note that this was way more speculative :)
- steeleduncan 5y agoYes, it is a shame that no version of that purely functional Haskell ideal has been created that could reasonably be used for kernel development. Using the type system to constrain side effects of code in the way you suggest would eliminate massive classes of security vulnerabilities and crashes.
- Quekid5 5y agoCopilot is used for hard real time systems. Now, Copilot is probably more specialized than even kernel dev, but AFAICT there's not really any hard barrier there. "Just" a question of effort.
- staticassertion 5y agoIO is necessary because of purity, but it's in no way enabled by it. You don't need purity to have the IO monad, and you don't need purity to enforce that IO is defined in a type signature.