I have a sequence of X()
actions during which certain buttons might be grabbed (and not released afterwards). In order to prevent buttons from ending up grabbed, I therefore have to ungrab every button at the end, for example:
action1 >> action2 >> action3 >> ungrabAllButtons
I wish to encode this requirement as a type, so that action1
, action2
, action3
can only be used if the buttons are ungrabbed afterwards. That is, even though action1
, action2
, are really X()
actions, I would like them not to be usable as such unless they are wrapped in something like the following (borrowing Python's with
keyword):
withGrabbedButtons :: ??? -> X()
withGrabbedButtons action =
action >> ungrabAllButtons
-- correct ; complete_action does not leave the mouse grabbed
complete_action :: X()
complete_action = withGrabbedButtons (action1 >> action2 >> action3)
-- type error!
erroneous_single_action :: X()
erroneous_single_action = action1
-- type error!
erroneous_action :: X()
erroneous_action = action1 >> action2 >> action3
This is so that people do not accidentally use action1
, action2
, action3
as X()
actions, while forgetting to ungrab the buttons afterwards.
Is this possible with Haskell's type system? Thanks beforehand.