6 ms·
When writing some IO bound application, async Rust is great. Less great for libraries that want to support both async and sync without having to make an async
by xedrac 3y ago
When writing some IO bound application, async Rust is great. Less great for libraries that want to support both async and sync without having to make an async runtime a dependency if you just want the sync interface. Mutually exclusive features are taboo unfortunately. One thing I really love about Haskell is you can make any function run in a green thread by simply composing it with the 'async' function. There's nothing special about it. This works much better than say Go, because Haskell is immutable.
- XorNot 3y agoI'm not clear what your last sentence has to do with anything else? What does immutability have to do with Async/sync conversions?
- throwaway0665 3y agoyou can fearlessly run code on another thread if you're not worried it's going to cause a data race or mutate anything
- XorNot 3y agoThis is very much not free though. Predicting memory usage in Haskell programs is notoriously tricky (and all the memory copies aren't free either).
- c-cube 3y agoIt's also the case with OCaml, Elixir, clojure, etc. Non lazy languages can also have a rich collection of immutable data structures and have more predictable memory usage than Haskell. On the other hand, Go doesn't have a culture or features that encourage immutability.
- bippihippi1 3y agoit's not free, but it is explicit. it's nice for the code to explicitly define how the memory is being modified. there are copies in java too, you just have to know how the runtime works to know what each line does.
- ric2b 3y agoCopies in haskell are not explicit at all, though?
- whateveracct 3y agoPredicting memory usage in Haskell programs isn't actually tricky. At least, I stopped thinking so once I became an intermediate Haskeller. It's not that hard to have a mental model of the Haskell RTS the same as you'd have the JVM. Having the ability to do so generally is tablestakes for being an intermediate professional programmer imo. In university, I had to draw diagrams explaining the state of the C stack and heap after each line of code. That's the same thing. And I was 19 lmao. It's not hard. Maybe you're referring to space leaks? I've run into like 2 in my ten year Haskell career, and neither hit prod I've actually seem more Go and Java space leaks/OoM bugs hit prod than Haskell - despite having fewer total years using those languages than Haskell! Nobody blamed the language for those though :/
- polygamous_bat 3y agoImmutability is great for multithreaded/async programs because every thread can rest assured knowing no other thread can sneakily modify objects that they are operating on currently.
- candiddevmike 3y agoGo can prevent this with the race detector among other things
- stouset 3y agoSometimes.
- binary132 3y agoThe race detector needs to actually encounter a race in order to detect it, it's not a complete static analysis.
- omginternets 3y agoDetectors detect, they don’t prevent. All detectors suffer misses.
- IlliOnato 3y agoHow Haskell deals with access to shared resources which are mutable by their nature, like file system, or the outside world? (A honest question, I start to think that I'd like to learn more on this language)
- andyferris 3y agoAFAIK they tend to operate through the IO monad, which serves to order read/write events and mark parts of your code as interacting with the global mutable state that lives outside your program. So the mutable (or is it “volatile”?) environment is there, but you explicitly know when and where you interact with it.
- whateveracct 3y ago
- deleted 3y ago[deleted]
- jeremyjh 3y agoAll threads in Haskell are green. Async just gives you another way to get return values from threads without having to use MVars or Chans.
- anon291 3y ago> This works much better than say Go, because Haskell is immutable. The immutability has nothing to do with async. Async is for IO threads. If you want pure parallelism you use `par`. But Haskell IO threads (forkIO and friends) are also green when run with GHC.
- xedrac 3y agoAsync is definitely nicer when things are immutable. On modern CPUs, async green threads can easily be backed by different OS threads running in parallel on different CPU cores, making data races a real problem for many languages. Async does not guarantee that things will not be run in parallel, although you shouldn't rely on it for explicit parallelism.
- anon291 3y agoHaskell async is run in IO though in which mutability is allowed. Async itself is mutable.
- fulafel 3y agoI'm not sure it's worth it even for most IO bound applications. The first couple of IO bound examples that come to mind (an app doing bulk disk or network IO, eg sequential file access or bulk data transfer) would logically seem to work just as well without async since the bottleneck is the disk or network card or connection. I'd guess it could be an advantage for high concurrency applications that are CPU bound, but could be made IO bound by optimizing the userspace code. But OS threads are pretty efficient and you can have zillions of them, so the async upside is quite bounded, so this niche would seem smallish.