Replies: 5 comments 2 replies
-
I gave this some thought before writing that wiki page as well, and indeed, there's no particular reason to only allow I agree there may be use-cases for lazy messages. However, I do believe the 'most obvious way' to send messages must enforce them to be fully evaluated. It's way too easy to send a message to another process which then forces evaluation in said process, i.e., pushing CPU consumption there, which I think is not as it should be (the sender should pay said price), and secondly, evaluation could fail ( So, I do believe the There could, of course, be a |
Beta Was this translation helpful? Give feedback.
-
As for STM: using this doesn't really impact the messages being transferred. However, I do believe it's something to use in the implementation to get things "right". As an example, a process setting the If a mailbox can be polled in STM, this means a process' |
Beta Was this translation helpful? Give feedback.
-
STM (Software Transactional Memory) and NFData (Normal Form Data) are used for message passing in Haskell because they provide important guarantees and optimizations for concurrent programming. STM ensures that all memory operations within a transaction either succeed atomically or fail atomically, without any possibility of intermediate states being visible to other threads. This provides a higher level of consistency and avoids issues like race conditions and deadlocks. NFData ensures that data is fully evaluated to its normal form, which can help avoid performance issues with lazy evaluation in a concurrent setting. While lazy evaluation and optional transactions may have their uses, they also introduce additional complexity and potential issues that STM and NFData can help avoid. Overall, the use of STM and NFData in message passing provides a solid foundation for safe and efficient concurrent programming in Haskell. |
Beta Was this translation helpful? Give feedback.
-
Incidentally, after asking this question I had an issue with a lazy bottom crashing the receiver of a TChan, resulting in the wrong behavior, so I think it's good to force NFData :) For STM, I guess the downside is performance, as benchmarked in https://github.com/jberryman/unagi-chan#performance . Though the benefit may outweigh this overhead. |
Beta Was this translation helpful? Give feedback.
-
For me, having an STM procedure to read inbox is a way to have a multi-wait without wrapping everything in Async.race manually. E.g. A "driver" actor may want to poll its inbox, but also wait for a bunch of external events. |
Beta Was this translation helpful? Give feedback.
-
Raised by @TristanCacqueray in https://discourse.haskell.org/t/towards-an-actor-framework-for-haskell/5929/10, based on the content of https://github.com/NicolasT/troupe/wiki/Design-Ideas/.
Beta Was this translation helpful? Give feedback.
All reactions