-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make algebra interfaces verified by default (#4739)
Previously there were interfaces for Semigroup, Monoid, etc, that were just syntactic in nature, requiring only that operations like <+> or elements like neutral exist. There was a corresponding set of "verified" interfaces requiring that the expected laws actually hold. Thus Semigroup required that the <+> operation exist, while VerifiedSemigroup required that that operation actually be associative. Such an arrangement is annoying for two reasons. First, extra paperwork. If I want to show that something really is a semigroup, I have to write two implementation blocks, the "plain" version and the "verified" version. On the other side, if I want to add a new interface, then in order to keep with the existing style I need to write both a "plain" version and a "verified" version. In some cases, like AbelianGroup, the "plain" interface is empty, since it doesn't add any new syntactic elements. Second, proof. Suppose a type has been declared to be a Semigroup, but VerifiedSemigroup hasn't been implemented for it. What can be assumed about that type? Is its <+> operation associative or not? If it isn't, why call it a semigroup? If it is, why not prove it? And if it can't be proved, how do we know that it's true? The big selling point of Idris is its expressive type system and strong compile-time guarantees, so let's take advantage of that and verify by default. Fixing the interfaces is easy -- just move the "verified" requirements into the "plain" interface, and that's it. In some cases there were implementations of the "verified" interfaces, and those could also easily be copied over. More challenging are the cases for which there were no verified implementations. There are three ways of dealing with them: (1) Come up with the required proofs. This was done, for example, with `Semigroup a => Semigroup (Vect n a)` etc in contrib/Data/Matrix/Algebraic.idr, and also with easy ones like Maybe and Endomorphism. (2) Replace the interface with an "unverified" version, thereby highlighting the fact that the expected properties have not been proven. This was done with a few complicated data structures in contrib, like MaxiphobicHeap and SortedBag, as well as with primitive numeric types like Integer. (3) Assert without proof that the laws hold using believe_me and really_believe_me. This was done for cases in prelude and base for which proofs are impossible (eg String) or not obvious (eg Morphism and Kleislimorphism). Needless to say, these proofs should be implemented where possible. If these assertions are disliked, I would be happy to convert them to "unverified". Note that this change only applies to those interfaces that belong to "abstract algebra": semigroups, monoids, groups, and so on. There is a whole other set of "plain"/"verified" interfaces dealing with structures from "category theory". Those should also undergo this unification, but I don't know how to do it just yet.
- Loading branch information
Showing
25 changed files
with
555 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.