3 ms·
Of course you can have purity in JavaScript. This function is referentially transparent and pure: (a, b) => a + b; While this function is not pure: (ms
by goto11 5y ago
Of course you can have purity in JavaScript. This function is referentially transparent and pure:
(a, b) => a + b;
While this function is not pure:
(msg) => console.log(msg)
However by your definition I guess the above function is actually also pure, since it can be passed around and manipulated without executing it?
The cool thing about Haskell is that purity can be statically guaranteed by the type system and that unpure function are explicitly marked as such in their type signature.
- papamonad 5y agoThat function isn't referentially transparent as enforced by the language/compiler, doing no effects in a function isn't the same as having a referentially transparent function. Nothing is stopping you from logging/introducing side effects in (a,b) => a + b; you chose not to which doesn't make it referentially transparent. Being enforced or statically guaranteed is what makes haskell have purity and js not have it.