on :: Event a -> (a -> IO ()) -> Interval ()
on e f = do
    latch <- liftIO $ newIORef Nothing
    defer $ listen (pulse e) $ \y -> do
        x <- swapIORef latch y
        case (x, y) of
            (Just a, Nothing) -> f a
            _                 -> return ()
on :: Event a -> (a -> IO ()) -> Interval ()
on e f = do
    latch <- liftIO $ newIORef Nothing
    defer $ listen (pulse e) $ \y -> do
        x <- swapIORef latch y
        case (x, y) of
            (Just a, Nothing) -> f a
            _                 -> return ()
on e f = do
    latch <- liftIO $ newIORef Nothing
    defer $ listen (pulse e) $ \y -> do
        x <- swapIORef latch y
        case (x, y) of
            (Just a, Nothing) -> f a
            _                 -> return ()