Skip to main content Accessibility help
×
×
Home

COCHIS: Stable and coherent implicits

  • TOM SCHRIJVERS (a1), BRUNO C.D.S. OLIVEIRA (a2), PHILIP WADLER (a3) and KOAR MARNTIROSIAN (a4)
Abstract

Implicit programming (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.

Copyright
References
Hide All
Andreoli, J.-M. (1992) Logic programming with focusing proofs in linear logic. J. Logic Comput. 2, 297347.
Barendregt, H. (1981) The Lambda Calculus: Its Syntax and Semantics, volume 103 of Studies in Logic and the Foundations of Mathematics. North-Holland.
Barendregt, H., Dekkers, W. & Statman, R. (2013) Lambda Calculus with Types. Cambridge University Press.
Biernacki, D. & Polesiuk, P. (2018) Logical relations for coherence of effect subtyping. Log. Methods Comput. Sci. 14(1), pp. 128.
Boehm, H.-J. (1985) Partial polymorphic type inference is undecidable. In 26th Annual Symposium on Foundations of Computer Science. IEEE, pp. 339345.
Bottu, G.-J., Karachalias, G., Schrijvers, T., Oliveira, B. & Wadler, P. (2017) Quantified class constraints. In Proceedings of the 10th ACMSIGPLAN International Symposium on Haskell, Haskell. New York, NY, USA: ACM, pp. 148161.
Bottu, G.-J. & Simon, P. J. (2018) Quantified constraints – proposals [online]. Available at: https://github.com/Gertjan423/ghc-proposals/blob/quantified-constraints/proposals/0000-quantified-constraints.rst#overlap
Brady, E. (2015) Type classes in Idris [online]. Available at: https://groups.google.com/forum/#!topic/idris-lang/OQQ3oc6zBaM
Breazu-Tannen, V., Coquand, T., Gunter, C. & Scedrov, A. (1991) Inheritance as implicit coercion. Inform. Comput. 93, 172221.
Camarão, C. & Figueiredo, L. (1999) Type inference for overloading without restrictions, declarations or annotations. In FLOPS. London, UK: Springer-Verlag, pp. 3752.
Chakravarty, M., Keller, G. & Peyton Jones, S. L. (2005a). Associated type synonyms. In ICFP. New York: ACM, pp. 241253.
Chakravarty, M., Keller, G., Peyton Jones, S. L. & Marlow, S. (2005b) Associated types with class. In POPL. New York: ACM, pp. 113.
Chong, S. (2017) Lecture 2: Logical relations Part 2 [online]. Available at: https://www.seas.harvard.edu/courses/cs252/2017fa/lectures/lec02-contextual-equiv.pdf
Damas, L. & Milner, R. (1982) Principal type-schemes for functional programs. In POPL. New York: ACM, pp. 207212.
Devriese, D. & Piessens, F. (2011) On the bright side of type classes: Instance arguments in Agda. In ICFP. New York: ACM, pp. 143155.
Dijkstra, A. & Swierstra, S. D. (2005) Making Implicit Parameters Explicit. Tech. rept. Utrecht University.
Dreyer, D., Harper, R., Chakravarty, M. & Keller, G. (2007) Modular type classes. In POPL. New York: ACM, pp. 6370.
Dunfield, J. & Krishnaswami, N. R. (2013) Complete and easy bidirectional typechecking for higherrank polymorphism. In ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Morrisett, G. & Uustalu, T. (eds), Boston, MA: ACM, pp. 429442.
Eisenberg, R. A., Vytiniotis, D., Peyton, J. S. & Weirich, S. (2014) Closed type families with overlapping equations. In POPL. New York: ACM, pp. 671683.
Garcia, R., Jarvi, J., Lumsdaine, A., Siek, J. & Willcock, J. (2007) An extended comparative study of language support for generic programming. J. funct. program. 17(2), 145205.
GHC. (2017a) Ghc users guide: Overlapping instances [online]. Available at: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#overlapping-instances
GHC. (2017b) Quantified constraints – GHC [online]. Available at https://ghc.haskell.org/trac/ghc/wiki/QuantifiedConstraints
Gonthier, G., Ziliani, B., Nanevski, A. & Dreyer, D. (2011) How to make ad hoc proof automation less ad hoc. In Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming, ICFP’11. New York: ACM, pp. 163175.
Gregor, D., Järvi, J., Siek, J. G., Stroustrup, B., Dos Reis, G. & Lumsdaine, A. (2006) Concepts: Linguistic support for generic programming in c++. In OOPSLA. New York: ACM, pp. 291310.
Hindley, J. R. (1969) The principal type-scheme of an object in combinatory logic. Trans. Am. Math. Soc. 146, 2960.
Hulley, B. (2009) A show-stopping problem for modular type classes? [online]. Available at: http://lists.seas.upenn.edu/pipermail/types-list/2009/001405.html
Jones, M. P. (1992). A theory of qualified types. In Proceedings of the 4th European Symposium on Programming (ESOP ’92), Krieg-Brückner, B. (ed), London, UK: Springer-Verlag, pp. 287306.
Jones, M. P. (1995a) Qualified Types: Theory and Practice. Cambridge University Press.
Jones, M. P. (1995b) Simplifying and improving qualified types. In Proceedings of the Seventh International Conference on Functional Programming Languages and Computer Architecture (FPCA ’95). New York, NY, USA: ACM, pp. 160169.
Jones, S. P., Vytiniotis, D., Weirich, S. & Shields, M. (2007) Practical type inference for arbitraryrank types. Journal of Functional Programming 17(1), 182.
Kahl, W. & Scheffczyk, J. (2001). Named instances for Haskell type classes. In Preliminary Proceedings of the 2001 ACM SIGPLAN Haskell Workshop (HW’2001), Hinze, R. (ed), Technical Report UU-CS-2001-23. Firenze, Italy: Institute of Information and Computing Sciences, Utrecht University.
Kiselyov, O. & Shan, C.-C. (2004) Functional pearl: Implicit configurations–or, type classes reflect the values of types. In Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell. Haskell ’04, ACM, pp. 3344.
Kmett, E. (2015) Type classes vs. the world [online]. Available at: https://www.youtube.com/watch?v=hIZxTQP1ifo
Le Botlan, D. & Rémy, D. (2003) MLF: Raising ML to the power of system F. In Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming. ICFP ’03. SIGPLAN Not. 49, 4. pp. 5263.
Leijen, D. (2008) HMF: Simple type inference for first-class polymorphism. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP ’08). New York, NY, USA: ACM, pp. 283294.
Lewis, J., Launchbury, J., Meijer, E. & Shields, M. (2000) Implicit parameters: Dynamic scoping with static types. In POPL. New York: ACM, pp. 108118.
Liang, C. & Miller, D. (2009) Focusing and polarization in linear, intuitionistic, and classical logics. Theor. Comput. Sci. 410(46), 47474768.
Manna, Z. & Waldinger, R. (1980) A deductive approach to program synthesis. Acm Trans. Program. Lang. Syst. 2(1), 90121.
Marlow, S. (2012) Safe Haskell and instance coherence [online]. Available at: https://mail.haskell.org/pipermail/haskell-cafe/2012-October/103887.html
Martelli, A. & Montanari, U. (1982). An efficient unification algorithm. Acm Trans. Program. Lang. Syst. 4(2), 258282.
Miller, D. (1992) Unification under a mixed prefix. J. Symb. Comput. 14(4), 321358.
Miller, D., Nadathur, G., Pfenning, F. & Scedrov, A. (1991) Uniform proofs as a foundation for logic programming. Ann. Pure Appl. Logic 51(1–2), 125157.
Milner, R. (1978) A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17(3), 348375.
Morris, J. G. & Jones, M. P. (2010) Instance chains: Type class programming without overlapping instances. In ICFP. New York: ACM, pp. 375386.
Morris, J. H., Jr. (1969) Lambda-calculus Models of Programming Languages. Ph.D. thesis, Sloan School of Management.
Research, Mozilla, Team. (2017) The rust programming language [online]. Available at: https://www.rust-lang.org/en-US/
Norell, U. (2008) Dependently typed programming in Agda. In Proceedings of the 6th International Conference on Advanced Functional Programming (AFP’08), Koopman, P., Plasmeijer, R. & Swierstra, D. (eds), Berlin, Heidelberg: Springer-Verlag, pp. 230266.
nponeccop. (2012) Breaking data.set integrity without generalizednewtypederiving [online]. Available at: https://stackoverflow.com/questions/12735274/breaking-data-set-integrity-withoutgeneralizednewtypederiving
Odersky, M. (2010) The Scala Language Specification, version 2.8.
Odersky, M., Blanvillain, O., Liu, F., Biboudis, A., Miller, H. & Stucki, S. (2017) Simplicitly: Foundations and applications of implicit function types. Proc. ACM Program. Lang. 2(POPL), 42:142:29.
Odersky, M. & Läufer, K. (1996) Putting type annotations to work. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’96). New York, NY, USA: ACM, pp. 5467.
oleg. (2006) Typeclass vs. prolog programming [online]. Available at: https://mail.haskell.org/pipermail/haskell-cafe/2006-September/018500.html
Oliveira, B. C. d. S., Moors, A. & Odersky, M. (2010) Type classes as objects and implicits. In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA ’10). New York, NY, USA: ACM, pp. 341360.
Oliveira, B. C. d. S., Schrijvers, T., Choi, W., Lee, W. & Yi, K. (2012) The implicit calculus: A new foundation for generic programming. In PLDI ’12. New York: ACM.
Peyton Jones, S. L., Jones, M. P. & Meijer, E. (1997) Type classes: An exploration of the design space. In Haskell Workshop, Launchbury, J. (ed), Amsterdam, pp. 116.
Pfenning, Frank. (1993) On the undecidability of partial polymorphic type reconstruction. Fundam. Inform. 19(1/2), 185199.
Pierce, B. C. (2002) Types and Programming Languages. Cambridge, MA: MIT Press.
Reynolds, J. C. (1991) The coherence of languages with intersection types. In Proceedings of the International Conference on Theoretical Aspects of Computer Software. TACS ’91. London, UK: Springer-Verlag, pp. 675700.
Rouvoet, A. (2016) Programs for Free: Towards the Formalization of Implicit Resolution in Scala. M.Phil. Thesis. TU Delft, the Netherlands.
Scharli, N., Ducasse, S., Nierstrasz, O. & Black, A. P. (2003) Traits: Composable units of behaviour. In European Conference on Object-Oriented Programming (ECOOP 2003). Springer, pp. 248274.
Schrijvers, T., Peyton Jones, S. L., Chakravarty, M. & Sulzmann, M. (2008) Type checking with open type functions. In ICFP. New York: ACM.
Siek, J. G. (2011) The C++0x “Concepts”˙I Effort [online]. Available at: http://ecee.colorado.edu/~siek/concepts_effort.pdf
Siek, J. G. & Lumsdaine, A. (2005) Essential language support for generic programming. In PLDI. New York: ACM, pp. 7384.
Sozeau, M. & Oury, N. (2008) First-class type classes. In Proceedings of the 21st International Conference on Theorem Proving in Higher Order Logics (TPHOLs ’08), Ait Mohamed, O., Muñoz, C. & Tahar, S. (eds), Berlin, Heidelberg: Springer-Verlag, pp. 278293.
Sulzmann, M., Duck, G., Peyton Jones, S. L. & Stuckey, P. J. (2007) Understanding functional dependencies via Constraint Handling Rules. J. Funct. Program. 17, 83129.
Vytiniotis, D., Peyton Jones, S., Schrijvers, T. & Suzmann, M. (2011) OutsideIn(X): Modular type inference with local assumptions. J. Funct. Program. 21(4–5), 333412.
Vytiniotis, D., Weirich, S. & Peyton Jones, S. (2008) FPH: First-class polymorphism for Haskell. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming. ICFP ’08, ACM, pp. 295306.
Wadler, P. (2015) Propositions as types. Commun. ACM 58(12), 7584.
Wadler, P. L. & Blott, S. (1989) How to make ad-hoc polymorphism less ad hoc. In POPL. New York: ACM, pp. 6076.
Wehr, S., Lämmel, R. & Thiemann, P. (2007) JavaGI: Generalized interfaces for java. In ECOOP, Springer Verlag, pp. 347372.
White, L., Bour, F. & Yallop, J. (2014) Modular implicits. In Proceedings ML Family/OCaml Users and Developers Workshops, ML/OCaml 2014, Kiselyov, O. & Garrigue, J. (eds), Gothenburg, Sweden, September 4–5, 2014. EPTCS, pp. 22–63, vol. 198.
Zhang, E. (2014) Type classes: Confluence, coherence and global uniqueness [online]. Available at: http://blog.ezyang.com/2014/07/type-classes-confluence-coherence-global-/uniqueness/
Zhang, Y., Loring, M. C., Salvaneschi, G., Liskov, B. & Myers, A. C. (2015). Lightweight, flexible object-oriented generics. In Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’15, ACM, pp. 436445.
Recommend this journal

Email your librarian or administrator to recommend adding this journal to your organisation's collection.

Journal of Functional Programming
  • ISSN: 0956-7968
  • EISSN: 1469-7653
  • URL: /core/journals/journal-of-functional-programming
Please enter your name
Please enter a valid email address
Who would you like to send this to? *
×

Metrics

Altmetric attention score

Full text views

Total number of HTML views: 0
Total number of PDF views: 0 *
Loading metrics...

Abstract views

Total abstract views: 0 *
Loading metrics...

* Views captured on Cambridge Core between <date>. This data will be updated every 24 hours.

Usage data cannot currently be displayed

COCHIS: Stable and coherent implicits

  • TOM SCHRIJVERS (a1), BRUNO C.D.S. OLIVEIRA (a2), PHILIP WADLER (a3) and KOAR MARNTIROSIAN (a4)
Submit a response

Discussions

No Discussions have been published for this article.

×

Reply to: Submit a response


Your details


Conflicting interests

Do you have any conflicting interests? *