Open Philonous opened 8 years ago
In the stackoverflow discussion HeinrichApfelmus said
Note that if several networks are allowed, then it is problematic to return a Behavior from [run], because you could try to use it in another network, which will fail horribly.
While this is true, the MonadIO instance of MomentIO allows Behaviours and Events to leak anyway. Also, if the network description can be spread across multiple MomentIO blocks, it would be severly limiting (if not defeating the point outright) if they could not transported between them.
A solution to this problem might be to tag Events and Behaviours with a phantom type similar to ST. That strikes me as rather heavy-weight, though.
A solution to this problem might be to tag Events and Behaviours with a phantom type similar to ST. That strikes me as rather heavy-weight, though.
Yeah. That would be the solution I have in mind, too, but we already had phantom parameters at one point, and I think the library is much easier to use without them. Hence, I would like to take the alternative approach of "type safety by oscurity", that is making the possible bad things difficult to discover.
Not having a (canonical) way of getting Events and Behaviors from one MomentIO block to another would make the whole idea pointless, though, as one could only create disjoint networks.
Maybe adding a salient warning to the documentation that Events and Behaviours must only be used in MomentIO blocks belonging to their respective EventNetworks, and maybe adding run-time checks that throw meaningful exceptions if this requirement is violated would do the trick?
I came to the realization that this function, or a function like it, is required for some use cases, e.g. integrating more tightly with GUI libraries.
I actually banged my head against this a while back and came up with something that seems to work: https://github.com/Philonous/reactive-banana/commit/2ff7317e50348d2221f66875bbf5c6a7e747e900 .
If this is the right way to go I can clean the patch up a bit and create a PR.
A new primitive to run MomentIO computations in compiled networks would be useful:
It can already be simulated as shown in this gist