[Haskell-beginners] dynamic set of objects in netwire
Nathan Hüsken
nathan.huesken at posteo.de
Wed Nov 7 15:47:30 CET 2012
Hey,
I need (in netwire) a way to handle a dynamic set of objects. Therefor I
need a way of growing and shrinking the set. Since I have little
experience with Haskell and FRP, I would appreciate some input.
Shrinking is not problem, as I can just remove wires that inhibit. But
how to let the set grow?
So far, my main loop would look like this:
I have input data
data Input = UpdatePhysic | KeyDown Int ...
and the main Wire which creates objects on certain inputs and updates
the physics when UpdatePhysics is send:
mainWire :: WireP Input
mainWire = proc input -> do
userControlledObject <- userControlledObjectWire -< input
if input == UpdatePhysics then do
rec
letCollData = ...
physicsObjects <- physicsObjectsWire -< collData
else
empty -<
My idea for the dynamics set wire is this:
data Subwire e m a b = forall a'. Subwire (a -> a') (Wire e m a' b)
dynamicSet :: (Monad m) => (c -> Subwire e m a b) -> Wire e m
(Either a c) b
The Idea is that the dynamicSet in every invocation either creates wires
or steps them:
mainWire :: WireP Input
mainWire = proc input -> do
userControlledObject <- userControlledObjectWire -< input
rec
let collisionData = ...
objects <- dynamicSet -< if input == UpdatePhysics then Left
collisionData else Right input
So far so good, what bothers me is, that when I have several dynamicSets
(different kind of objects) I have to make several if input == ... then
... else ... constructs, which feels repeative.
I would welcome some input on how to structure the main loop and/or
dynamic set...
Regards,
Nathan
More information about the Beginners
mailing list