[Haskell-beginners] FRP and a set of pairwise interacting (colliding) objects

Ertugrul Söylemez es at ertes.de
Mon Jul 2 10:51:00 CEST 2012


Nathan Hüsken <nathan.huesken at posteo.de> wrote:

> So I would have a main arrow like this (leaving out the Map for which
> I have to lookup the syntax):
>
> main = proc in -> do
>        planet1 <- planets initPlanet1 -< allPlanets
>        planet2 <- ...
>        ...
>        allPlanets <- delay [] -< [planet1,planet2 ...]
>
> (I would probably have some arrow managing all planets instead of
> listing them separately)
> Correct?

Yes, that's the basic idea.  Just drop in a 'rec' somewhere for the
feedback to work.

> Yes, that makes sense. There is still a little overhead. Assuming
> collisions are symmetric, the OOP approach would only test every pair
> of planets once ... not in the way I wrote it down, but it could
> easily be changed so that it does.
> But here they have to tested twice.
> Thats only factor 2 and probably acceptable. Still, is it avoidable?

Yes, it is.  You can write a managing wire transformer (along the lines
of the ones from Control.Wire.Trans.Combine) specifically for colliding
objects.  It's really much easier than it sounds.  Just have a look into
the source code of that module.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120702/eae5ad16/attachment.pgp>


More information about the Beginners mailing list