5 ms·
one of the points of the article is wrong, fp isn't stateless at all it just tends to represent state in a different way - look at monads in haskell.
by doctorKrieger 12y ago
one of the points of the article is wrong, fp isn't stateless at all it just tends to represent state in a different way - look at monads in haskell.
- wyager 12y agoWell Haskell can still "stateless" in some sense, even if your program seems to take advantage of state. The State monad (and other monads), for example, just facilitate a bit of clever syntax to sneak computational context, which can include state, into the lambda calculus. The IO and STM monads (which deal with side effects) are a bit different, and can introduce true state into a program (with a bit of cleverness to make the existence of state mesh well with the lambda calculus).
- innguest 12y agoNo, it is indeed stateless. The fact that it represents state is proof of that. FP uses representations for things instead of the real things. For instance, OO purposefully causes changes in RAM to make things happen, where in FP changes in RAM are incidental and the programmer need not manage them. So it is stateless because you program indirectly by using these conceptual representations that are free of implementation.
- dllthomas 12y agoModulo IORef and similar.
- innguest 12y agoNo, even IORef is stateless. You will know if there's state in a language if you can build a function that returns different results given the same values over time; IORef does not allow you to do that.
- dllthomas 12y agoThe bit that I was intending to modify was your statement that "in FP changes in RAM are incidental and the programmer need not manage them". With IORef, changes in RAM are not incidental, and the programmer is explicitly managing them. If IORef isn't direct enough for you, substitute Ptr. The fact that it happens in the runtime system does not necessarily mean that it is incidental or that it does not need to be managed by the programmer. As to your broader claim here, I while I understand what you're getting at (and probably wouldn't have bothered responding, but for the above) I think it's most precise to say that IORef is an encoding of state. This does not have to mean that state gets updated by means of side effects.