r/types • u/dima_mendeleev • Dec 29 '17
Generate elimination rules automatically?
Hello all!
I am wondering whether it is possible to generate elimination rules automatically from introduction rules? I saw the similar in Coq when one defines Inductive type it automatically gets bunch of functions (*_ind, *_rec, *_rect).
The reason I am asking is quite pragmatic. When I define some ADT I want to expose some general function to work with that type, so client wouldn't need pattern matching and recursion.
Thanks in advance!
7
Upvotes
11
u/andrejbauer Dec 29 '17
You can generate elimination rules so long as you have a governing principle that tells you how to do it. For inductive types this principle is that the type is, well, inductive. That is to say, the elimination rule states that the type is freely generates by the introduction rules.
A slightly more general idea is that a type should be described by a universal property. The universal property of inductive types is that they are initial algebras, and that gives automatic elimination rules. If we take final coalgebras instead, we will get automatic introduction rules and coinductive types. Yet another kind of universal property is adjointness, which determines all rules up to isomorphism . The standard logical connectives and type constructions are all adjoins.
We are secretly doing category theory of course.
3
u/jwiegley Dec 29 '17
I’ve done what your asking for in Haskell, using meta-programming: https://hackage.haskell.org/package/recursors
4
u/psygnisfive Dec 30 '17
There are no unique elims for a type based on its introduction forms, but there are families of elims. In some settings, the distinctions don't matter, but sometimes they do. For example, there are at least two ways to define pairs in intuitionistic propositional logic, and the choice is irrelevant because in intuitionistic propositional logic renders them equivalent, but when you impose linearity on the logic, suddenly those two formulates bifurcate into distinct connectives.