Re:Functional Programming Doesn’t Work (and what to do about...
by almost on Tuesday December 29, 2009 @02:48PM
(#1021115)
That's not quite fair though, the problem as he states it is to do this after you've written the program. So while yes, you could use the State Monad that might not be a trivial change to the code. Things might be even worse if the function was already written in another Monad, Monad Transformers can be just a little tricky. Unless of course you write everything in the State Monad just in case you ever have to do anything like that :)
These are both easy tasks in Haskell. Just use the state monad. You also get 100% certainty that the state isn't leaking into places where you didn't want it to leak to.
Lack of controlled mutable state is a failure of Erlang, not functional programming.
Also, counting function calls would actually be fairly straightforward in Erlang as well. You create a process which counts function calls to B. A then queries this process when it needs to find out how many function calls were made to B. Slightly harder to program, but it works even in the distributed setting.