[Haskell-beginners] netwire and "dynamic" list of objects

Nathan Hüsken nathan.huesken at posteo.de
Tue Apr 10 17:07:47 CEST 2012

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
       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]
       --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
       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.


On 04/10/2012 01:57 PM, Ertugrul Söylemez wrote:
> Nathan Hüsken <nathan.huesken at posteo.de> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

More information about the Beginners mailing list