Typing deep pattern-matching in presence of polymorphic variants
Jacques Garrigue · 2004
Polymorphic variants are a well-known feature of the Objective Caml programming language, and they have turned popular since their introduction. They allow structural equality of algebraic type definitions, and code reuse through their polymorphism. Their typing and compilation have been studied in the past, and there are already detailed published works for both2),4). By their very nature, polymorphic variants depend on patternmatching to analyze their contents. However, only typing for shallow pattern-matching was studied in the past. In that case, checking exhaustiveness is trivial, and the natural typing rule guarantees it. Deep pattern-matching is more complex, as other constructors may appear nested in the same pattern-matching. Exhaustiveness check is available, but only after finishing type checking, while we would like to use it to define the typing of polymorphic variant patterns. We explain the tradeoffs, and define a type checking algorithm for pattern-matching containing polymorphic variants which is symmetric.