Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 2
    The same way it deals with state in synchronous code Commented Jan 3, 2018 at 9:54
  • 3
    How can you decrement without serialising the operations? The simple answer is, "you can't". Operations on shared variables always have to be serialised with some sort of locking. And in-keeping with your previous question, such code ceases to be "functional", since the program result becomes dependent on undeclared variables: the starting state of the counter, and the timing of when each concurrent user submits the request. Commented Jan 3, 2018 at 10:31
  • 2
    This is probably too broad, it seems like you're after a description of how Software Transactional Memory works. Also, your tags are inappropriate - as you've phrased this question language-agnostically, consider removing the haskell and clojure tags. Commented Jan 3, 2018 at 11:57
  • 2
    STM would probably be the most common approach to this in FP (the main advantage being that FP code should be able to transparently handle the retries that are required for STM without worrying about repeated side effects). Commented Jan 3, 2018 at 12:04
  • 3
    Along with your other question, you can't just go line by line (or even block by block) and translate imperative code to functional code (if you could we'd just write a compiler to do it for us). The concepts are different, not just the idioms. You can certainly refactor an imperative codebase to a functional one, but you have to understand FP first. Learning FP is not like learning another imperative/OO language ("how do I say this in blub?"). If you want to migrate to haskell and or clojure you're going to have to start from the ground up and actually learn them. Commented Jan 3, 2018 at 13:19