<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 10 Mar 2019 at 20:20, P Orrifolius <<a href="mailto:porrifolius@gmail.com">porrifolius@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, 6 Mar 2019 at 02:30, Ivan Perez <<a href="mailto:ivanperezdominguez@gmail.com" target="_blank">ivanperezdominguez@gmail.com</a>> wrote:<br>
><br>
> Hi<br>
><br>
> Partly related; for recent work we did two things:<br>
><br>
> - Model part of the collision avoidance logic of a satellite as a state machine, implement it in haskell (14 locs) and use small check to verify that the state transitions fulfill the properties we expect for collision avoidance.<br>
><br>
> - Model small sats as Monadic Stream Functions [1], implement a communication protocol on top (also using MSFs), and use quickcheck + fault injection to verify distributed consensus in the presence of faults. The next (immediate) step will be to bound the trace length and use smallcheck or something that exhausts the input space. I have also implemented Raft using MSFs, and the idea is to verify properties in a similar way.<br>
><br>
> I know this is vague. Let me know if you have any questions or want more details.<br>
<br>
An appropriately vague response for a vague question! :)<br>
<br>
No, that's good, thanks.  I have considered using an FRP library for<br>
the _implementation_ but I couldn't really get my head around how I<br>
would use it for modelling and checking the protocol itself. </blockquote><div><br></div><div>Well, the basic idea of MSFs is that they are just a function: MSF m a b = a -> m (b, MSF m a b).</div><div><br></div><div>That means we can very easily prove properties about them. For example, we've proven the arrow laws (<a href="http://www.cs.nott.ac.uk/~psxip1/papers/msfmathprops.pdf">http://www.cs.nott.ac.uk/~psxip1/papers/msfmathprops.pdf</a>). If you want to mechanize proofs, it's helpful to have support for coinduction in your language.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> I was<br>
considering reflex as it seems to be well regarded, and the<br>
browser/mobile capabilities appear to be good which could prove useful<br>
for me in the future.  I'm not sure how reflex is classified but I<br>
guess it's a 'classic' FRP system, so perhaps the issues I was facing<br>
would be analogous to those when using MSF/dunai.<br></blockquote><div><br></div><div>Well, here my position would be a bit biased, of course. But there's good reason why we created dunai. Our position with dunai is that there is a more fundamental construct that a lot of existing ideas emerge from. We have seen that many FRP implementations can functionally be expressed in terms of MSFs, or MSFs + some extension (which you are more than welcome to implement, since the library is extensible by design).<br><br></div><div>We use this for GUI-stuff. All the time. It's actually one of the initial use cases that motivated creating dunai. Plus, you can run Yampa on top of dunai. So, we have Yampa mobile games running linked using bearriver (a Yampa-compatible FRP layer). Yampa (and dunai) also runs on the browser (see the GHCjs branch of haskanoid). I have also a layer for the GUI-oriented reactive library Keera Hails. It's quite fast too. For a recent paper, I had to run complex physics simulations in Yampa, and this was clocked at 60Hz rendering (vsync) and about 10000 simulation cycles per frame (meaning 60K simulation cycles per second).<br></div><div><br></div><div>Even though MSFs look arrowized, an MSF with unit input is a stream, and with time in the environment it is a signal. It's also a functor and an applicative. So you can write the same classic FRP style, if you want.<br></div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

Your email has made me take a second look at a FRP option, and I think<br>
I was seeing problems where there aren't any.<br>
<br>
One difficulty I perceived was the heterogeneity of the participants<br>
in the protocol and the multi-point communications, well beyond a<br>
simple sending/receiving distinction.<br>
That worries me less now.  It seems that if I could come up with a<br>
statechart description of each participant it's probably a fairly<br>
mechanical process to represent that in a FRP network.<br>
Perhaps that explains why I couldn't find many libraries to do with<br>
more 'elaborate' state representations (as in statecharts are more<br>
elaborate than FSM/automata/etc).  Maybe once you reach that<br>
complexity they're not the best way to think about the problem in<br>
Haskell.<br>
<br>
The 'complex heterogeneity' reinforced my main problem, which now I<br>
think might just be a case premature optimisation.  It seemed that if<br>
I wanted to enumerate all states while testing the protocol I would<br>
need to 'branch' each participant whenever they changed and<br>
recursively test each temporal alternative... and that probably<br>
involved building, modifying, reorganising, restoring networks on the<br>
fly.  Maybe achievable, but I couldn't immediately see how.  But a<br>
simple succession of root-to-tip searches/executions of that tree<br>
could be perfectly adequate.<br>
Just have to try it out but I think I was getting carried away.<br>
<br>
Anyway, after that additional vagueness... a bit of a tangent. :)<br>
One problem I have with the Haskell ecosystem is I end up falling down<br>
the rabbit-hole whenever I start researching something.  And within<br>
each rabbit-hole I find more<br>
interesting-thing-to-research-rabbit-holes, and within them... etc,<br>
etc.  Soon I'm so deep down the rabbit-holes I'm smothered in quantum<br>
foam and don't know which way is up.<br>
On my last foray I started with MSF and came upon Streamly:<br>
<a href="https://hackage.haskell.org/package/streamly-0.6.0" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/streamly-0.6.0</a><br>
Are you familiar with it?</blockquote><div><br></div><div>I have not explored it yet. But it seems related. Just for info, there's a package called Rhine that extends Dunai with type-safe parallelism and asynchronicity. It ensures that communications specify buffers that are compatible.<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">  To my inexperienced eye it seems quite<br>
similar to MSF/dunai, do you have any thoughts on it?  Relative merits<br>
in different use cases?<br>
Reflex appeals to me because of the possibility of learning it and<br>
leveraging it's UI layers in other projects.  But for a protocol<br>
implementation it feels like maybe I should be using something more,<br>
um... stripped back/fundamental.<br>
<br>
Again, thanks for the reply.<br></blockquote><div><br></div><div>My pleasure! Let me know if you have any questions.<br><br></div><div>I'd recommend that you take a look at these papers:<br><br></div><div>- "FRP Refactored": <a href="https://dl.acm.org/citation.cfm?id=2976010">https://dl.acm.org/citation.cfm?id=2976010</a> (the original MSF paper, shows classic and arrowized FRP)<br></div><div>- "Rhine: FRP with type-level clocks": <a href="https://dl.acm.org/citation.cfm?id=3242757">https://dl.acm.org/citation.cfm?id=3242757</a> (asynchronicity, concurrency and parallelism with MSFs)<br></div><div>- "Testing and debugging FRP": <a href="https://dl.acm.org/citation.cfm?id=3110246">https://dl.acm.org/citation.cfm?id=3110246</a> (quickcheck + temporal logic + FRP)<br></div><div>- "Fault Tolerant FRP": <a href="https://dl.acm.org/citation.cfm?id=3236791">https://dl.acm.org/citation.cfm?id=3236791</a><br></div><div><br></div><div>I'm happy to provide copies of these papers if you want them :) My website (<a href="http://www.cs.nott.ac.uk/~psxip1/">http://www.cs.nott.ac.uk/~psxip1/</a>) should have links to all of them.<br><br></div><div>All the best,<br><br></div><div>Ivan<br></div></div></div></div></div></div></div></div></div>