[Haskell-cafe] functions making their own memos

MarLinn monkleyon at gmail.com
Sun Jul 8 09:04:19 UTC 2018


> So this would generate a large circular movement:
>
> circularMovement :: MovementFunc
>
> This generates a small wobble.
>
> wobble :: MovementFunc
>
> Then I can compute the final position once per animation frame by
> superimposing or composing individual movements:
>
> computePosition :: [MovementFunc] -> Time -> IO Position

Is there any specific reason why you can't compute the wobbles all at 
once beforehand? I'm thinking something along the lines of FRP:

type Behaviour a  = Time -> a
type MovementFunc = Behaviour RelativeMovement

So you still have wobble :: MovementFunc, but MovementFunc is pure. And 
you combine them not with (.) but with (<*>):

mergeMovements :: [Behaviour RelativeMovement] -> Behaviour RelativeMovement
mergeMovements = (mconcat .) . sequenceA

computePosition :: [Behaviour RelativeMovement] -> Behaviour Position
computePosition movements time = moveBy (mergeMovements movements time) origin

Look, Ma, I'm still not using any IO! Wheeee!

Cheers,
MarLinn



More information about the Haskell-Cafe mailing list