3 ms·
Frankly, my reason for using Rust is not memory semantics (I'd be happy for most applications with a Gc), it's the type system. I could be writing in Haskell f
by Yoric 4y ago
Frankly, my reason for using Rust is not memory semantics (I'd be happy for most applications with a Gc), it's the type system.
I could be writing in Haskell for an even more powerful type system, of course, (especially now that Haskell has gained linear types) but the language never took hold outside of academia.
- kaba0 4y agoWell, “never took hold” is relatively. It is and will likely always be a niche language, but one with a quite big audience and ecosystem. There are people happily using different languages that are much smaller, they just happen to occupy a less academic niche — e.g. I’m guessing but you probably don’t have such feelings against D, when it might very well be smaller than Haskell.
- Yoric 4y agoTo clarify, I have actually coded a bit in Haskell and I have actually released open-source code in SML/NJ, a commercial application in OCaml and worked (as a very minor contributor) on industrial code in Coq. But if I have to start a new industrial project, I will most likely use Rust, because it is easier to hire and because there is lots of momentum in the Rust ecosystem, which means that there are crates for just about everything.
- ben0x539 4y agoI know this is facile, and it's speaking as someone with a lot more enthusiasm about than expertise with Haskell, but whenever I write some toy Haskell code and have to think about "remember to close this file handle before the end of this block" or "make sure not to use this file handle outside this block (because we just used a combinator to close it)", I'm baffled that Rust has mostly figured out that whole class of problem before Haskell
- tome 4y ago> I'm baffled that Rust has mostly figured out that whole class of problem before Haskell Have you heard of `withFile`? https://www.stackage.org/haddock/lts-20.16/base-4.16.4.0/System-IO.html#v:withFile https://www.stackage.org/haddock/lts-20.16/base-4.16.4.0/Sys...
- Yoric 4y agoNote that a `Handle` can escape from `withFile` (unless perhaps this library has been updated to use linear types, I haven't followed Haskell in a while). That being said, even without linear types, it's much harder to accidentally leak a scoped value in Haskell than in most other programming languages, as the leak shows up in the type signature. /pedantic
- tome 4y ago> Note that a `Handle` can escape from `withFile` Yes, this is true. If someone really wanted they could write a version that didn't using an ST-like type variable trick. I guess it hasn't been considered sufficiently necessary.
- ben0x539 4y agoYeah, that's what my second gripe was meant to complain about. Really, withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r is just a more general way of writing withFile :: FilePath -> IOMode -> (Handle -> IO Handle) -> IO Handle ;) I've also heard about the ResourceT monad transformer but as of right now I don't think I could explain what it does or judge how well it does it, maybe that's also a sufficient solution.