3 ms·
Monad and Functor make some additional promises, beyond what can be expressed in the types, that some users rely on. In the same way that we expect addition of
by dllthomas 5y ago
Monad and Functor make some additional promises, beyond what can be expressed in the types, that some users rely on.
In the same way that we expect addition of numbers to obey the commutative law and associative law. (Except, of course, that floats don't...)
- valenterry 5y agoFloats are a great example actually. Implementing "unlawful monads" would be equal to giving someone a float and telling them "you can use this like a rational number from math". And in fact it might work for the longest time - until it doesn't (think rounding-errors and similar) and then the confusion will be big. With monads it's the same, but potentially even worse, because it's rather easy to test float addition behavior, but for certain monads that can be much harder.
- marcosdumay 5y agoHaskell has a library called monad-validate that I think is a great example for both what the monad laws are important for, and how it's important that one understand their reasons, instead of just following advice literally on every possible situation. Just as yo want to break addition commutativity so you can approximate real numbers, there are times when you want something to behave like a monad, but not follow its laws.