Hostname: page-component-8448b6f56d-qsmjn Total loading time: 0 Render date: 2024-04-24T05:22:28.178Z Has data issue: false hasContentIssue false

OutsideIn(X) Modular type inference with local assumptions

Published online by Cambridge University Press:  16 May 2011

DIMITRIOS VYTINIOTIS
Affiliation:
Microsoft Research (e-mail: dimitris@microsoft.com)
SIMON PEYTON JONES
Affiliation:
Microsoft Research
TOM SCHRIJVERS
Affiliation:
Universiteit Gent
MARTIN SULZMANN
Affiliation:
Informatik Consulting Systems AG
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

Advanced type system features, such as GADTs, type classes and type families, have proven to be invaluable language extensions for ensuring data invariants and program correctness. Unfortunately, they pose a tough problem for type inference when they are used as local type assumptions. Local type assumptions often result in the lack of principal types and cast the generalisation of local let-bindings prohibitively difficult to implement and specify. User-declared axioms only make this situation worse. In this paper, we explain the problems and – perhaps controversially – argue for abandoning local let-binding generalisation. We give empirical results that local let generalisation is only sporadically used by Haskell programmers. Moving on, we present a novel constraint-based type inference approach for local type assumptions. Our system, called OutsideIn(X), is parameterised over the particular underlying constraint domain X, in the same way as HM(X). This stratification allows us to use a common metatheory and inference algorithm. OutsideIn(X) extends the constraints of X by introducing implication constraints on top. We describe the strategy for solving these implication constraints, which, in turn, relies on a constraint solver for X. We characterise the properties of the constraint solver for X so that the resulting algorithm only accepts programs with principal types, even when the type system specification accepts programs that do not enjoy principal types. Going beyond the general framework, we give a particular constraint solver for X = type classes + GADTs + type families, a non-trivial challenge in its own right. This constraint solver has been implemented and distributed as part of GHC 7.

Type
Articles
Copyright
Copyright © Cambridge University Press 2011

References

Bachmair, L. & Tiwari, A. (2000) Abstract congruence closure and specializations. In Proceedings of International Conference on Automated Deduction (CADE '00), LNCS, vol. 1831. Springer-Verlag, pp. 6478.Google Scholar
Beckert, B. (1994) A completion-based method for mixed universal and rigid E-unification. In Proceedings of International Conference on Automated Deduction (CADE '94). Springer-Verlag, pp. 678692.Google Scholar
Chakravarty, M., Keller, G. & Peyton Jones, S. (2005a) Associated type synonyms. In Proceedings of International Conference on Functional Programming (ICFP '05). New York: ACM, pp. 241253.Google Scholar
Chakravarty, M., Keller, G., Peyton Jones, S. & Marlow, S. (2005b) Associated types with class. In Proceedings of ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '05). New York: ACM, pp. 113.Google Scholar
Cheney, J. & Hinze, R. (2003) First-Class Phantom Types. TR 1901. Cornell University. Available at: http://techreports.library.cornell.edu:8081/Dienst/UI/1.0/Display/cul.cis/TR2003-1901Google Scholar
Damas, L. & Milner, R. (1982) Principal type-schemes for functional programs. In Proceedings of ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '82). New York, NY, USA: ACM, pp. 207212.Google Scholar
Faxén, K.-F. (2003) Haskell and principal types. In Proceedings of the 2003 ACM SIGPLAN Workshop on Haskell (Haskell '03). New York, NY, USA: ACM, pp. 8897.CrossRefGoogle Scholar
Frühwirth, T. (1998) Theory and practice of Constraint Handling Rules. J. Logic Program. 37 (1–3), 95138.CrossRefGoogle Scholar
Gallier, J. H., Narendran, P., Raatz, S. & Snyder, W. (1992) Theorem proving using equational matings and rigid E-unification. J. ACM 39 (2), 377429.CrossRefGoogle Scholar
Hall, C. V., Hammond, K., Peyton Jones, S. L. & Wadler, P. L. (1996) Type classes in Haskell. ACM Trans. Program. Lang. Syst. 18 (2), 109138.CrossRefGoogle Scholar
Heeren, B., Leijen, D. & van IJzendoorn, A. (2003) Helium, for learning Haskell. In Proceedings of ACM SIGPLAN 2003 Haskell Workshop. New York: ACM, pp. 6271.CrossRefGoogle Scholar
Jones, M. P. (September 1992) Qualified Types: Theory and Practice. DPhil thesis, Oxford University.Google Scholar
Jones, M. P. (September 1993) Coherence for Qualified Types. Research Report YALEU/DCS/RR-989. New Haven, CT: Yale University.Google Scholar
Jones, M. P. (2000) Type classes with functional dependencies. In Proceedings of European Symposium on Programming Languages and Systems (ESOP '00), LNCS, vol. 1782. Springer-Verlag.Google Scholar
Kapur, D. (1997) Shostak's congruence closure as completion. In Proceedings of International Conference on Rewriting Techniques and Applications (RTA '97). London, UK: Springer-Verlag, pp. 2337.CrossRefGoogle Scholar
Kennedy, A. J. (September 1996) Type Inference and Equational Theories. LIX RR/96/09. Ecole Polytechnique.Google Scholar
Kiselyov, O., Peyton Jones, S. & Shan, C.-C. (2010) Fun with type functions. In Reflections on the work of C. A. R. Hoare, Roscoe, A. W., Jones, Cliff B. & Wood, Ken (eds). Springer, 303333.Google Scholar
Lämmel, R. & Peyton Jones, S. (2003) Scrap your boilerplate: A practical design pattern for generic programming. In Proceedings of ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI '03). New York: ACM, pp. 2637.Google Scholar
Lämmel, R. & Peyton Jones, S. (2005) Scrap your boilerplate with class: extensible generic functions. In Proceedings of ACM SIGPLAN International Conference on Functional Programming (ICFP '05). New York, NY, USA: ACM, pp. 204215.Google Scholar
Läufer, K. & Odersky, M. (1994) Polymorphic type inference and abstract data types. ACM Trans. Program. Languages Syst. 16 (5), 14111430.CrossRefGoogle Scholar
Lin, C.-K. & Sheard, T. (2010a) Pointwise generalized algebraic data types. In Proceedings of ACM SIGPLAN workshop on Types in language design and implementation (TLDI '10). New York, NY, USA: ACM, pp. 5162.CrossRefGoogle Scholar
Lin, C.-K. & Sheard, T. (July 2010b) Three Techniques for GADT Type Inference. Draft.Google Scholar
Maher, M. (2005) Herbrand constraint abduction. In Proceedings of Annual IEEE Symposium on Logic in Computer Science (LICS '05). IEEE Computer Society, pp. 397406.CrossRefGoogle Scholar
Milner, R. (1978) A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17 (3), 348375.CrossRefGoogle Scholar
Nieuwenhuis, R. & Oliveras, A. (2005) Proof-producing congruence closure. In Proceedings of International Conference on Rewriting Techniques and Applications (RTA '05). LNCS, vol. 3467. Springer-Verlag, pp. 453468.Google Scholar
Nipkow, T. & Prehofer, C. (1995) Type reconstruction for type classes. J. Funct. Program. 5 (2), 201224.CrossRefGoogle Scholar
Odersky, M., Sulzmann, M. & Wehr, M. (1999) Type inference with constrained types. Theor. Pract. Object Syst. 5 (1), 3555.3.0.CO;2-4>CrossRefGoogle Scholar
Peyton Jones, S., Vytiniotis, D., Weirich, S. & Shields, M. (January 2007) Practical type inference for arbitrary-rank types. J. Funct. Program. 17 (1), 182.CrossRefGoogle Scholar
Peyton Jones, S., Vytiniotis, D., Weirich, S. & Washburn, G. (2006) Simple unification-based type inference for GADTs. In Proceedings of ACM SIGPLAN International Conference on Functional Programming (ICFP '06). ACM, pp. 5061.Google Scholar
Peyton Jones, S., Washburn, G. & Weirich, S. (July 2004) Wobbly Types: Type Inference for Generalised Algebraic Data Types. Technical Report MS-CIS-05-26. Philadelphia, Pennsylvania: University of Pennsylvania.Google Scholar
Pottier, F. & Régis-Gianas, Y. (2006) Stratified type inference for generalized algebraic data types. In Proceedings of ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '06). ACM, pp. 232244.Google Scholar
Pottier, F. & Rémy, D. (2005) The essence of ML type inference. In Advanced Topics in Types and Programming Languages, Pierce, B. C. (ed), Chapter 10. MIT Press, pp. 389489.Google Scholar
Schrijvers, T., Guillemette, L-J. & Monnier, S. (2008b) Type invariants for Haskell. In Proceedings of Workshop on Programming Languages Meets Program Verification (PLPV '09). New York, NY, USA: ACM, pp. 3948.Google Scholar
Schrijvers, T., Peyton Jones, S., Chakravarty, M. & Sulzmann, M. (2008a) Type checking with open type functions. In Proceedings of ACM SIGPLAN International Conference on Functional Programming (ICFP '08). New York, NY, USA: ACM, pp. 5162.CrossRefGoogle Scholar
Schrijvers, T., Peyton Jones, S., Sulzmann, M. & Vytiniotis, D. (2009) Complete and decidable type inference for GADTs. In Proceedings of ACM SIGPLAN International Conference on Functional Programming (ICFP '09). ACM.Google Scholar
Schrijvers, T., Sulzmann, M., Peyton Jones, S. & Chakravarty, M. (2007) Towards open type functions for Haskell. In Proceedings of International Symposium on Implementation and Application of Functional Languages (IFL '09), Chitil, O. (ed), pp. 233251.Google Scholar
Simonet, V. & Pottier, F. (2007) A constraint-based approach to guarded algebraic data types. ACM Trans. Program. Lang. Syst. 29 (1).CrossRefGoogle Scholar
Skalka, C. & Pottier, F. (2003) Syntactic type soundness for HM(X). Electron. Notes Theor. Comput. Sci. 75, 6174.CrossRefGoogle Scholar
Stuckey, P. J. & Sulzmann, M. (2005) A theory of overloading. ACM Trans. Program. Lang. Syst. 27 (6), 154.CrossRefGoogle Scholar
Sulzmann, M. (May 2000) A General Framework for Hindley/Milner Type Systems with Constraints. Ph.D. thesis, Department of Computer Science, Yale University.CrossRefGoogle Scholar
Sulzmann, M., Chakravarty, M., Peyton Jones, S. & Donnelly, K. (2007a) System F with type equality coercions. In Proceedings of ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI '07). ACM.Google Scholar
Sulzmann, M., Duck, G. J., Peyton Jones, S. & Stuckey, P. J. (2007b) Understanding functional dependencies via constraint handling rules. J. Funct. Program. 17 (1), 83129.CrossRefGoogle Scholar
Sulzmann, M., Müller, M. & Zenger, C. (1999) Hindley/Milner Style Type Systems in Constraint Form. Research Report ACRC-99-009. School of Computer and Information Science, University of South Australia.Google Scholar
Sulzmann, M., Schrijvers, T. & Stuckey, P. J. (2006a) Principal type inference for GHC-style multi-parameter type classes. In Proceedings of Asian Symposium on Programming Languages and Systems (APLAS '06). LNCS, vol. 4279. Springer-Verlag, pp. 2643.CrossRefGoogle Scholar
Sulzmann, M., Schrijvers, T. & Stuckey, P. (January 2008) Type Inference for GADTs via Herbrand Constraint Abduction. Report CW 507. Leuven, Belgium: Department of Computer Science, K.U. Leuven.Google Scholar
Sulzmann, M., Wazny, J. & Stuckey, P. (2006b) A framework for extended algebraic data types. In Proceedings of International Symposium on Functional and. Logic Programming (FLOPS '06). LNCS, vol. 3945. Springer-Verlag, pp. 4764.CrossRefGoogle Scholar
Tofte, M. (1990) Type inference for polymorphic references. Inf. comput. 89 (1), 134.CrossRefGoogle Scholar
Vytiniotis, D., Peyton Jones, S. & Schrijvers, T. (2010) Let should not be generalized. In Proceedings of ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI '10). New York, NY, USA: ACM, pp. 3950.CrossRefGoogle Scholar
Wadler, P. & Blott, S. (1989) How to make ad-hoc polymorphism less ad hoc. In Proceedings of ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '89). ACM.Google Scholar
Weirich, S., Vytiniotis, D., Peyton Jones, S. & Zdancewic, S. (2010) Generative type abstraction and type-level computation. In Proceedings of ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '10). ACM.Google Scholar
Wright, A. (1995) Simple imperative polymorphism. Lisp Symb. Comput. 8, 343355.Google Scholar
Xi, H., Chen, C. & Chen, G. (2003) Guarded recursive datatype constructors. In Proceedings ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '03). ACM, pp. 224235.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.