Download PDF

Journal of Functional Programming

Publication date: 2019-02-08
Volume: 29
Publisher: Cambridge University Press (CUP)

Author:

Schrijvers, Tom
Oliveira, Bruno CDS ; Wadler, Philip ; Marntirosian, Koar

Keywords:

Science & Technology, Technology, Computer Science, Software Engineering, Computer Science, LANGUAGE SUPPORT, UNIFICATION, INFERENCE, 0102 Applied Mathematics, 0103 Numerical and Computational Mathematics, 0803 Computer Software, Software Engineering, 4612 Software engineering, 4613 Theory of computation

Abstract:

Implicit Progamming (IP) mechanisms infer values by type-directed resolution, making programs more compact and easier to read. Examples of IP mechanisms include Haskell's type classes, Scala's implicits, Agda's instance arguments, Coq's type classes, and Rust's traits. The design of IP mechanisms has led to heated debate: proponents of one school argue for the desirability of strong reasoning properties; while proponents of another school argue for the power and flexibility of local scoping or overlapping instances. The current state of affairs seems to indicate that the two goals are at odds with one another and cannot easily be reconciled. This paper presents COCHIS, the Calculus Of CoHerent ImplicitS, an improved variant of the implicit calculus that offers flexibility while preserving two key properties: coherence and stability of type substitutions. COCHIS supports polymorphism, local scoping, overlapping instances, first-class instances, and higher-order rules, while remaining type safe, coherent and stable under type substitution. We introduce a logical formulation of how to resolve implicits, which is simple but ambiguous and incoherent, and a second formulation, which is less simple but unambiguous, coherent and stable. Every resolution of the second formulation is also a resolution of the first, but not conversely. Parts of the second formulation bear a close resemblance to a standard technique for proof search called focusing. Moreover, key for its coherence is a rigorous enforcement of determinism.