This repo contains two implementations of the Santa Claus Problem as Simon Peyton Jones implemented it in his wonderful paper, Beautiful Concurrency:
-
The first one is in the
Basicmodule. It is more or less the same as SPJ's implementation, but as I noticed text interleaving when I implemented this as described in the paper (and because it was fun and good practice), I ended up adding a STM-based logger. This uses aTQueueand a forked thread that simply checks if there is a message ready to be printed endlessly, printing when one shows up.
I'm not sure why the examples shown in the original paper don't do the same text interleaving that I saw--I can only imagine that the underlying implementation ofIOchanged from the time the paper was originally written--but after implementing it this way I read thatData.Text.IOdoes not behave this way, so I may have been able to simply swap out theputStrcalls with the equivalentTextversions...but this is a thread (cough) I didn't pull on. If you know more about this I'd love to hear more though! -
The other implementation was my attempt to turn this into a more sophisticated app using a reough approximation of the
ReaderTpattern, along with introducingUnliftIOso I could runAsyncactions (in particular forking theelfandreindeeractions initiated by the parentsantaaction) within the app Monad I created, which let me streamline logging, for one. At this size of an app this is certainly overkill, and I suspect there is more I should add here to ensure this is safe in terms of exception handling in particular...I may add more as I go as this is really just a way for me to learn how this kind of an implementation may work.
In any case, I'd love any feedback anyone may have, especially suggestions on how to improve the more complex app implementation.