Over the years I occasionally reimplemented my rdf-triple-browser, first in GWT, then Java/Swing and then last summer in Haskell using Threepenny-gui (which I will call ‘TPG’ for the rest of this article). The hardest part for me was understanding how to connect to external events.
The documentation says
newEvent :: IO (Event a, Handler a) “Create a new event. Also returns a function that triggers an event occurrence.” What is doesn’t say it that calling the returned
Handler causes the specific returned
Event to happen.
I got lost in the documentation about
Handler, going off on dead ends with
register. Even the TAs at last summer’s Utrecht Haskell Summer School could not figure it out (although, to be fair, they did not spend that much time on it, they were concentrating on course questions).
Fortunately, Max Taldykin, on stackoverflow, provided a small program that lead me to discover the “magic” of how to use what is returned via
newEvent. Below I show an even smaller program that shows how it is wired.