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

Nathan Hüsken nathan.huesken at posteo.de
Mon Apr 9 18:40:52 CEST 2012


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

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)
    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
        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?


More information about the Beginners mailing list