r/javascript • • Aug 27 '16

Is your JavaScript function actually pure?

http://staltz.com/is-your-javascript-function-actually-pure.html
8 Upvotes

48 comments sorted by

View all comments

16

u/kpmah Aug 27 '16

I would say this is a bit of a meaningless distinction and that the function is pure. You can always break assumptions if you try hard enough. e.g. in Haskell:

Prelude System.IO.Unsafe System.Random> let sum = foldl (+) 0
Prelude System.IO.Unsafe System.Random> sum [unsafePerformIO randomIO, unsafePerformIO randomIO]
1658109205626070070
Prelude System.IO.Unsafe System.Random> sum [unsafePerformIO randomIO, unsafePerformIO randomIO]
8004505404486503573
Prelude System.IO.Unsafe System.Random> sum [unsafePerformIO randomIO, unsafePerformIO randomIO]
-7400902255149128526