
"Event" is a small DSL that I interpret in the back end. It allows me to write nice expressions about events. Say you have functions to create text fields and buttons on the GUI:
-- Create an event binded to a text field, with the first argument as a title. -- Once validated, the event returns the content of the text field. inputText :: String -> Event String
-- Create an event binded to a button, with the first argument as a title. inputButton :: String -> Event ()
You could then express nice combinations:
-- using Applicative: create a form with two fields data NameSurname = NameSurname String String form1 :: Event NameSurname form1 = NameSurname <$> onInputText "Name:" <*> onInputText "Surname:"
-- using Alternative: create two buttons, first button clicked returns False, the second True form2 :: Event Boolean form2 = True <$ inputButton "click here for True" <|> False <$ inputButton "click here for False"
-- using Monad: create the two buttons of form2, if "True" button is clicked, then a text field appears asking for a name. form3 :: Event String form3 = do myBool <- form2 if myBool then onInputText "Name:" else return "No name"
Oh, I see now. So we need to reflect on the structure of the computation, to figure out what widgets to show. That makes sense. Chris
But I am lacking a way to express the situation where I have a bunch of events, which can be cancelled as soon as a result can be calculated: ShortcutEvents :: [Event a] -> ([Maybe a] -> Maybe b) -> Event b
You can think of it as a generalization of the "or" shortcut, where the evaluation is cut short if the first argument evaluates to True.
With your type: type Event a = Maybe (BaseEvent a) Could you express the combinations above??