Events in Haskell, and How to Implement Them
Abstract
We describe a new and simpler implementation in Haskell of CML's events, which encode reactions by a thread to combinations of messages from other threads. We add a new type of Guarded Events, by which recipients can filter messages with conditions on their value known as Guards. We implement guarded channels. The guard type and the indexing algorithm are not part of the channel definition, so that the user can trade off what guards are required against the cost of indexing. As an example we sketch the encapsulation of a graphical user interface toolkit. This can be done concisely not only because of guarded events, but also because we construct events monadically. Monadic events are especially helpful for representing concurrent processes which transform themselves in reaction to external communications.