Skip to main content
17 events
when toggle format what by license comment
Oct 4, 2022 at 13:23 comment added Joseph Cooper This is not true even from a mathematical point of view: idempotence only makes sense for a function that has the same domain and codomain, e.g. int -> int, String -> String , User -> User. That is orthogonal to purity and if this definition of purity were correct a function like len: String -> int (which just gives the length of the input string) would not be pure!
Mar 6, 2019 at 19:48 comment added R.. GitHub STOP HELPING ICE In a (not purely functional) programming language, language-level functions from [args] to [retval] are actually mathematical functions from [args,old_global_state] to [retval,new_global_state]. Acknowledging this solves the debate going on here.
S Mar 6, 2019 at 12:18 history suggested gerrit CC BY-SA 4.0
fix typo "output". Also made the link more descriptive.
Mar 6, 2019 at 10:13 review Suggested edits
S Mar 6, 2019 at 12:18
Mar 5, 2019 at 14:39 comment added JLRishe In the context of programming, there are no "side effects", but if you were to expand the definition to include this, then a idempotent function and a pure function would mean the same thing. No, they wouldn't mean the same thing at all. Idempotent, not pure: void f(int var) { someGlobalVariable = var; }. Pure, not idempotent: int func1(int var) { return var + 1; }.
S Mar 5, 2019 at 14:27 history suggested IridescenceDeep CC BY-SA 4.0
Grammar fix
Mar 5, 2019 at 7:14 comment added gnasher729 There is the term "nilpotent" for functions where calling them zero times or one time (or 100 times) have the same effect. Idempotence usually implies not being nilpotent, or you would call it nilpotent.
Mar 5, 2019 at 0:15 review Suggested edits
S Mar 5, 2019 at 14:27
Mar 4, 2019 at 22:55 comment added Frax Purity and idempotence are different. A pure function doesn't have to be idempotent in mathematical sense (it is abviously idempotent in terms of side-effects, as it has none). Idempotent (in programming sense) function doesn't have to be pure, as in example given by OP. Also, as opa mentioned, idempotence is a useful property with a strictly different use than purity. Your definition of purity as "idempotent and with no side-effects" is wrong or at least misleading, downvoting.
Mar 4, 2019 at 20:29 comment added Tezra You should go into more detail about the difference between pure and idempotent. Your example func1 is not idempotent because func1(1) != func1(func1(1)).
Mar 4, 2019 at 14:39 comment added Krupip @Neil "Idempotency is strictly a mathematical term." No it isn't, its also used in networking and client server communication/distributed systems as well and is described as JörgWMittag describes it. Its a useful concept because it allows multiple requests to a server/client with the same operation/message with out changing what that original message set out to do. This is useful when you have unreliable communication, and you need to retry a command because either the clients message was dropped or the servers reply was.
S Mar 4, 2019 at 13:30 history suggested Cloudy CC BY-SA 4.0
Replaced comment reply with link to referenced answer
Mar 4, 2019 at 12:46 review Suggested edits
S Mar 4, 2019 at 13:30
Mar 4, 2019 at 9:00 comment added David Arno @JörgWMittag, the issue with the term, idempotent, is that it's effectively defined differently in imperative and function programming approaches as purity is assumed for the latter, but not for the former.
Mar 4, 2019 at 8:54 comment added Neil @JörgWMittag Idempotency is strictly a mathematical term. In the context of programming, there are no "side effects", but if you were to expand the definition to include this, then a idempotent function and a pure function would mean the same thing. Clearly that isn't the case as a pure function isn't only idempotent, but also has no side effects. As I see it, something is idempotent if you could never receive differing results for the same input after multiple calls. But I suppose we can agree to disagree on that point.
Mar 4, 2019 at 8:28 comment added Jörg W Mittag I think your definition of idempotency is too narrow, or put another way, you are using the mathematical definition of idempotency, not the programming one. For example, the PUT and DELETE HTTP methods are called idempotent precisely because executing their side-effects multiple times has the same effect as executing them only once. You are saying "idempotency means f∘f = f", whereas in programming, we mean "executing f has the same effect has executing f; f". Note that you can easily transform the second meaning into the former by adding a "world" parameter.
Mar 4, 2019 at 7:48 history answered Neil CC BY-SA 4.0