Hacker News new | past | comments | ask | show | jobs | submit login

Argh this sounds interesting but I’m not smart enough to make the connections. Could you dumb the explanation down a bit?



It's just saying that your type system is incomplete if it doesn't capture side effects. That is, if the function can do something that is not expressed as part of its return type, its return type is insufficiently expressive.

As an example, imagine an "updateDB" call that returns void. Totally could exist, and be useful, but all it does is a side effect; as a function you haven't expressed its functionality via its type. From a 'pure' perspective, it would be fair for the compiler to remove that call entirely, since you do nothing with the result (since there is no result). Instead you need a monad or something to express that side effect.

Obviously, many languages don't choose to express side effects within their type systems. It's not that means the language isn't useful, just that its type system isn't complete; you have things happening without a type attached to them (and in that way it's dynamically typed).


The problem is more that you cannot formally express your type system in such a case. The "pure" perspective you mentioned is basically the limited view that one can still work with when defining a type system. Side effects are then basically magic functions that have any necessary type (in fact, OCaml has such a function in its stdlib, called "magic", if I am not mistaken).


Monads don't help you there, though. Even Haskell doesn't capture the effect of "division by zero".

In the end, type systems (all of them, static as well as dynamic) are just a tradeoff between safety and practicality.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: