On 8 Jan 2008, at 3:38 PM, Achim Schneider wrote:
---$<---
or, while I'm at it
---$<---

moveBall :: State' -> State'
moveBall state =  state {ballPos' = (bpx+bvx, bpy+bvy)}
    where (bpx, bpy) = ballPos' state
          (bvx, bvy) = ballVel' state

idle'' :: StateRef -> IdleCallback
idle'' st = st $~ moveBall

---$<---

With the multiple IORef-Model, moveBall looks like this:

moveBall :: Vec2 -> Vec2 -> Vec2
moveBall (bpx, bpy) (bvx,bvy) = (bpx+bvx, bpy+bvy)

You can use this with the single IORef model, using the lifting function

liftMove :: (Vec2 -> Vec2 -> Vec2) -> IORef State -> IO ()
liftMove move r = withIORef r $ \ st -> st{ballPos = moveBall (ballPos st) (ballVel st) }

liftMove and moveBall can then be maintained separately; liftMove is part of your state framework (the outer layer of your program); moveBall is part of the algorithm specification (the inner layer of your program).

jcc

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to