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
Basic
module. 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 aTQueue
and 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 ofIO
changed from the time the paper was originally written--but after implementing it this way I read thatData.Text.IO
does not behave this way, so I may have been able to simply swap out theputStr
calls with the equivalentText
versions...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
ReaderT
pattern, along with introducingUnliftIO
so I could runAsync
actions (in particular forking theelf
andreindeer
actions initiated by the parentsanta
action) 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.