Answer the question
In order to leave comments, you need to log in
How is a GUI implemented in a pure stateless functional language (like Haskell)?
Can you tell me how a GUI can be implemented in a pure stateless functional language (like Haskell)? After all, the GUI needs a state (for example, an input field needs a variable in which the text entered in the input field will be saved).
I do not take into account situations when GUI libraries are written for Haskell in another, lower-level language (with state). I'm wondering how it is possible to implement a workable GUI element (same input field) in pure Haskell? And is it possible? I saw in the discussions a mention of the GUI in Haskell, but I did not understand what technique is behind this.
Answer the question
In order to leave comments, you need to log in
What makes you think that there is "no state" in Haskell? The monads ST, State (StateT transformer), and, of course, IO allow you to work with the state. It can work in places less productively, without any additional. guarantees, but this is a full-fledged working part of the language - a fact. And yes, ST and IO can be implemented in Haskell itself.
Instead of changing the value of a field in the structure, a new structure is created that duplicates all the fields from the old one, except for the field that needs to be changed.
You can make a pure function that will return the state of the form depending on the text of other fields, the state of checkboxes, mouse movement, and other external variables.
See "Functional Reactive Programming". Simply put, the program receives a stream of events and returns a stream of response actions.
For any language, there are libraries written at a lower level. For some languages there are more of them, for others - less.
I don’t know how libraries are made for Haskell, but you are interested in the aspect related to maintaining cleanliness when working with the GUI. At the level of language use, you can keep the purity by wrapping all "impure" calculations in monads, for example, in IO. It is convenient to use the representation, which in mathematics is called the Kleisli category, when the “impure” function A -> B turns into a pure A -> IO B. Examples were given by egorinsk in the comment above.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question