Conversation
|
Hello @werner291 . Thanks for the effort to put it together. Right now I don't have time to dive into this; will try to look at it in a few days. |
|
Ok, sorry about the long silence, there. I spent a couple days thinking about whether this was the best way forward, but some kind of limited monad should indeed be the simplest solution to doing this. The ability to create new state machines was indeed kinda missing. I briefly looked at whether purescript-behaviors did it better. At first I was surprised they weren't building their stuff in a monad, but they simply delay the creation of the state variables until the event/behavior is subscribed to, which causes state machines to be created once for every subscription. |
|
Hi @werner291 . Sorry for the very delayed response. I also ran into the problem of not being able to use subscriptions in a folding function. I think it would be a good idea to have something like Since you created this pull request, the underlying FRP implementation was esssentially replaced, so a new implementation of your idea will be also needed. However, I think the first step should be specifying the semantics a bit more. I see Reflex has a similar function, but it's not clear to me what are its semantics wrt subscription management. For example, I'm not sure whether we should keep previous subscriptions when receiving a new value. For example, suppose we have: -- assume e :: Event (Dynamic Int)
foldDynM (\d acc -> do
-- make it require a subscription
d' <- uniqDyn d
-- collect them in a list
pure (d' : acc)
) [] eThe question is: after |
Related to: #54
Here's a pull request with the changes I've made thus far that allow
foldDynto be called inside a frame update, addedfoldDynMwhich can create new dynamics when events are received.WORK IN PROGRESS This pull request, at the moment, is mostly meant as a way to comment on the proposed changes more easily, and represents an intent to eventually merge them in. The code is in a somewhat rough state and might need a bit of refactoring and/or reworking. I would strongly advise against merging it right now.
Done so far:
foldDyninto a monadMonadFoldfoldDynMwhich can be called in anyMonadFRP(might be possible to call insideMonadFoldas well with some modifications)foldDynMin an application (https://github.com/werner291/purechat/blob/f187423b67be44f1fb786ba97cfda9226332187a/src/API/ServerFeed.purs#L214) and confirmed it at least seems to work as intended.Points to do:
foldDyninto a monad is acceptable so far. Also, notice thatfoldDynnow pulls theupdateOrReadValueto make sure the current event is read, is that a valid thing to do in that situation?(f/h)old*functions and see how those can be made consistent witht he new changes.