logoalt Hacker News

ngruhntoday at 11:53 AM1 replyview on HN

You can't enforce purity on the type level in TypeScript and IIRC neither in Rust.


Replies

matt_kantortoday at 12:27 PM

You can't in Haskell either! For example, any function could secretly call `unsafePerformIO` to cause a side effect (and that's not the only example).

I believe `const` functions in Rust are actually be guaranteed to be pure, though I haven't followed that feature closely and there may be nuances.

In most languages purity is a norm rather than enforced by static analysis. I definitely agree that it's much safer to assume that an arbitrary Haskell function is pure than it is to assume that of an arbitrary TypeScript function.

show 1 reply