[Haskell-cafe] How to do this in FP way?

pierre k.pierre.k at gmail.com
Mon Jun 16 13:54:44 EDT 2008

On Mon, Jun 16, 2008 at 10:31:22AM +0800, Magicloud Magiclouds wrote:
> Hello,
>     I am getting familiar with FP now, and I have a "program design" kind of
> question.
>     Say I have something like this in C:
> static int old;
> int diff (int now) { /* this would be called once a second */
>   int ret = now - old;
>   old = now;
>   return ret;
> }
>     Because there is no "variable" in Haskell. So how to do this in a FP
> way?
> Thanks.

I think that "called once a second" suggests that you perhaps should
not do that in a FP way.

A state-changing function called frequently suggests that you are
perhaps doing something with a notion of time, maybe a game? Then FRP
is your FP approach. 

Or I would recommend you to explain your problem, because FP approach
could lie on much more higher level than one can figure out looking at
your short snippet.

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


More information about the Haskell-Cafe mailing list