background preloader

Codeanywhere · Cross Platform Cloud IDE

Color Combinations | Color Schemes | Color Palettes Why do we use persistent data structures in functional programming? I want to understand at a low level what would happen if the data structure is not persistent? Let's look at a pseudorandom number generator with a huge state space (like "Mersenne twister" with a state of 2450 bytes) as a data structure. We don't really want to use any random number more than once, so there seems to be little reason to implement this as an immutable persistent data structure. Now let's ask outselves what might go wrong in the following code: mt_gen = CreateMersenneTwisterPRNGen(seed) integral = MonteCarloIntegral_Bulk(mt_gen) + MonteCarloIntegral_Boundary(mt_gen) Most programming languages don't specify the order in which MonteCarloIntegral_Bulk and MonteCarloIntegral_Boundary will be evaluated. One can design an efficient mutable data structure for mt_gen such that any interleaving of the execution of MonteCarloIntegral_Bulk and MonteCarloIntegral_Boundary will give "a correct" result, but a different interleaving will in general lead to a different "correct" result.

Related: