
Hey, I have a simple SDL based graphic demo, which I am trying (for educational purposes) to rewrite utilizing netwire. The demo basically consists of a State which contains a list of object states. data ObjectState = ... data State = State [ObjectState] Then there is a function updateState which updates all objects, removing some and adding some new ones. updateState :: State -> State updateState (State oss) = State (catMaybes $ map updateObject $ newObjects ++ oss) where updateObject :: ObjectState -> Maybe ObjectState updateObject = ... newObjects :: [ObjectState] newObjects = ... OK, now I wrote a wire: type MyWire = Wire.Wire () (Kleisli IO) wire :: GameState -> MyWire () GameState wire initGS = proc _ -> do rec gs' <- Wire.delay initGS -< gs gs <- arr updateState -< gs' returnA -< gs Works wonderfully :). But I avoided rewriting "updateState" in wire format. But I have no Idea how to do that. How do I handle a dynamic list of objects in a wire? Thanks! Nathan

Nathan Hüsken
I have a simple SDL based graphic demo, which I am trying (for educational purposes) to rewrite utilizing netwire.
The demo basically consists of a State which contains a list of object states.
[...]
But I avoided rewriting "updateState" in wire format. But I have no Idea how to do that. How do I handle a dynamic list of objects in a wire?
Well, you are not really using FRP here. You are just forcing this application into the FRP model. Your only behavior is the application itself. This works, but buys you nothing. The first step to actually making use of FRP here is to get rid of the concept of "updating" something. Express your game objects themselves as wires: player :: GameWire (Input, [Wall]) Player wall :: GameWire a Wall enemy :: GameWire (Player, [Wall]) Enemy This allows you to write static game worlds. After that you can move to dynamic game worlds using wire transformers from Control.Wire.Trans.Combine. It is also pretty straightforward to write your own wire transformers for this purpose. You probably want to do that later -- just look at the source code. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/

Firstly, thanks for the answer. Ok, I made another attempt. I have a function, to output the state of one object: objectWire :: StdGen -> MyWire () ObjectState The random generator is used to create the initial state. Now I want to handle a dynamic set of objects. This is my attempt: wire :: MyWire () State wire = proc _ -> do rec rnds <- Wire.delay initRnds -< (tail rnds) let rnd = head rnds --Get a fresh random generator everytime --For now, only one new object every call let newObjWires = [objectWire rnd] rec --Start with newObjWires and add newObjWires everytime (1. Error) objWires <- Wire.delay newObjWires -< newObjWires ++ objWires oss <- distribute objWires -< () -- 2. Error Wire.identity -< GameState rnds ss where initRnds = stdgens $ mkStdGen 0 Now I get Not in scope: `newObjWires' at the 1. Error and Not in scope: `objWires' at the 2. Error. OK, I am guessing that I may not use newObjWires/objWires as parameters to the functions creating the wires. But I do not understand how to use any of Control.Wire.Trans.Combine to handle my dynamic set of wires. Regards, Nathan On 04/10/2012 01:57 PM, Ertugrul Söylemez wrote:
Nathan Hüsken
wrote: I have a simple SDL based graphic demo, which I am trying (for educational purposes) to rewrite utilizing netwire.
The demo basically consists of a State which contains a list of object states.
[...]
But I avoided rewriting "updateState" in wire format. But I have no Idea how to do that. How do I handle a dynamic list of objects in a wire?
Well, you are not really using FRP here. You are just forcing this application into the FRP model. Your only behavior is the application itself. This works, but buys you nothing.
The first step to actually making use of FRP here is to get rid of the concept of "updating" something. Express your game objects themselves as wires:
player :: GameWire (Input, [Wall]) Player wall :: GameWire a Wall enemy :: GameWire (Player, [Wall]) Enemy
This allows you to write static game worlds. After that you can move to dynamic game worlds using wire transformers from Control.Wire.Trans.Combine. It is also pretty straightforward to write your own wire transformers for this purpose. You probably want to do that later -- just look at the source code.
Greets, Ertugrul
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Hi there Nathan,
Nathan Hüsken
Ok, I made another attempt. I have a function, to output the state of one object:
objectWire :: StdGen -> MyWire () ObjectState
Minor note: You do not need to pass random number generators around. Netwire has native support for noise. See Control.Wire.Prefab.Random. A WRandom instance is predefined for IO. However I just realized a bug. I forgot to export the WRandom class. =) Will be fixed in the next release.
The random generator is used to create the initial state. Now I want to handle a dynamic set of objects. This is my attempt:
[...]
But I do not understand how to use any of Control.Wire.Trans.Combine to handle my dynamic set of wires.
While the context wire transformers allow you to have dynamic wire sets 'distribute' is pretty much static. In an older release of Netwire there used to be a 'manager' wire that was specifically designed to maintain a set of dynamic wires. I decided to omit it in newer releases and let library/application authors write a more domain-specific version of it. You should be able to just use the old code (perhaps with minor adjustments to fit the new types), which you can find here: <http://hackage.haskell.org/packages/archive/netwire/1.2.7/ doc/html/FRP-NetWire-Request.html> Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/
participants (2)
-
Ertugrul Söylemez
-
Nathan Hüsken