[Haskell-beginners] FRP and a set of pairwise interacting (colliding) objects
Nathan Hüsken
nathan.huesken at posteo.de
Sat Jun 30 10:42:37 CEST 2012
On 06/29/2012 04:47 PM, Ertugrul Söylemez wrote:
> Nathan Hüsken <nathan.huesken at posteo.de> wrote:
>
>> [...]
>>
>> But now the collisions are generated at one place, and processed at
>> another. This means that CollData must be somehow tagged to the
>> objects it belongs to (an ID for example). This again means that some
>> function must take the pool of all collision datas and distribute them
>> to the "object" Signals.
>>
>> When I have a lot of objects, this means a significant overhead!
>>
>> Now I am wondering if there is a nicer approach which avoids this
>> overhead.
> You can get around the overhead by letting the objects do the collisions
> themselves, much like in your OOP variant. For instance in Netwire you
> could have this:
>
> planets :: MyWire [Planet] Planet
>
> This naive way still causes the overhead of lists and a planet
> distinguishing between others and itself. But now this is simply a
> matter of choosing proper data structures and starting to identify
> planets:
>
> type PlanetSet = Map PlanetId Planet
>
> planets :: MyWire PlanetSet (PlanetId, Planet)
>
> This looks more promising. Now the last thing is that this looks like a
> chicken/egg problem, but it's easy to resolve using ArrowLoop and
> one-instant delays.
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 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?
Thanks!
Nathan
More information about the Beginners
mailing list