[Haskell-cafe] Re: Is there anyone out there who can translate C# generics into Haskell?

Jonathan Cast jonathanccast at fastmail.fm
Tue Jan 8 21:01:53 EST 2008


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



More information about the Haskell-Cafe mailing list