Here's the problem: the GUI button has a callback that switches its state from marked to unchecked.
In imperative programming languages, this is very simple to implement: just change the state of the button. For example:
void callback(Button btn) { btn.setChecked(!btn.getChecked()); }
But with purely functional programming, the callback cannot change the state of the object. The only thing the callback can do is create a new Button object with a new state. For example:
Button callback(Button btn) { return new Button(!btn.checked); }
The button created by the above callback will not be part of the graphical interface of the program, since the external function should receive the result of the callback and reintegrate the new value of the button into the graphical interface.
In addition, the button should not have callbacks with the above type signature, since button callbacks should be common. That is, the signature of the callback type will be:
Object callback(Object object);
The only solution I can think of in purely functional code is callbacks to accept and return a global GUI, for example:
GUI callback(GUI gui, Button btn) { ...bla bla bla recreate the gui tre ... }
So, how do I do this in purely functional code? how does my purely functional callback change the state of a button?
callback functional-programming
axilmar
source share