4 ms·
That's what I thought. It boils down to the question of whether: f => f() is a pure function? If so, then so is the author's example. If not, then I don't
by fenomas 10y ago
That's what I thought. It boils down to the question of whether:
f => f()
is a pure function? If so, then so is the author's example. If not, then I don't see how any JS function that takes an argument (and evaluates it) can be pure. Under that definition, I'm not sure it makes sense to talk about.
- masklinn 10y ago> If not, then I don't see how any JS function that takes an argument (and evaluates it) can be pure. A JS function could take an argument, use it but not evaluate it (or not evaluate it in all cases). `typeof` doesn't evaluate its argument for instance.
- fenomas 10y agoCertainly it could. I don't know what that has to do with my comment though.
- nilved 10y agoIs Haskell's `(++) :: [a] -> [a] -> [a]` pure? What if I pass `unsafePerformIO` to it? For theoretical purposes it might make sense to say pure functions cannot call impure functions, but I think a more practical definition includes functions that are provided as arguments.
- tamana 10y agoIf you introduce unsafe into a program, it is not pure. You can run a linter or something to check if your program uses unsafe anywhere. Purity is a spectrum, not a binary, The more impurities you add, the more likely your program will not behave reasonably (as in, not in accordance with the simple logical rules of referential transparency).
- fenomas 10y agoHaven't the faintest. I don't speak Haskell, 's why I asked. I'd thought pureness was a property of function definitions, irrespective of what they get passed, but living in Javascript land I've never had occasion to be concerned with the distinction. I kind of suspect it's not really something that's useful to talk about.
- nilved 10y agoNot asking you directly, I agree with you and was trying to rephrase the notion.