3 ms·
> If a piece of code uses Applicative or Monad you know it’s behaviour due to the Applicative/Monad mathematical laws. Well, we actually only know what it is s
by ReleaseCandidat 3y ago
> If a piece of code uses Applicative or Monad you know it’s behaviour due to the Applicative/Monad mathematical laws.
Well, we actually only know what it is supposed to do. The laws are not enforced, so it is perfectly possible to implement a type class that violates the laws of the type class.
- Quekid5 3y agoSeveral test frameworks implement Law Testing which will test your instances for lawfulness as long as you can generate instances of your data structures. E.g. https://hackage.haskell.org/package/hedgehog-classes https://hackage.haskell.org/package/hedgehog-classes . So you only need to be able to generate instances and you get comprehensive tests for free, so that's nice too. It is also the case that implementations of these very abstract classes typically only also have very few implementations that make any kind of sense type-wise and that the 'obvious' one is correct. (Just to preempt: Yes, tests aren't proof, but such is life without a full proof system in the language. In practice, I've found property-based testing sufficient.)
- ReleaseCandidat 3y agoOh, I know and I'm not arguing against anything you've said. I just wanted to express - for people who don't know Haskell - that while the laws exist, they are not (as of now ;) enforced or checked by the type checker.
- Quekid5 3y agoNo worries, I was also just trying to add info.