Pergunta

I'm writing a stream transformer from some Input data type to an Output data type. Input is made by the user, so there is some time between the events. Because each input requires some resource loading, I'd like to "look into the future", i.e. send all possible inputs to the main computation and preload resources based on the results.

Currently, there is always exactly one output after each input but it might eventually become interesting to change this.

I succeeded to implement that with the Automaton transformer by Ross Paterson. I'm not sure my solution is optimal.

  • Are there nice examples how to do this? Perhaps even with test code?
  • Can it be achieved with a monad as well? (Examples?, Explanation why it's impossible?)

Edit: After the call for more specifics, I added code here. Now I'm removing it (it was not understandable) and add some other explanation. My question is answered thaugh.

My intention was to have the main event loop stop after each user input that has been fed to the arrow/stream transformer/whatever. Then it would store the current automaton state and send all possible inputs (fake events) one by one to the automaton and see what resources must be loaded, to cache them. After the next real event, it would use the cache for better responsiveness. The main computation should not be influenced by this.

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top