Executable Relational Specifications of Polymorphic Type Systems Using Prolog

Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 9613)

Abstract

A concise, declarative, and machine executable specification of the Hindley–Milner type system (HM) can be formulated using logic programming languages such as Prolog. Modern functional language implementations such as the Glasgow Haskell Compiler support more extensive flavors of polymorphism beyond Milner’s theory of type polymorphism in the late 70’s. We progressively extend the HM specification to include more advanced type system features. An interesting development is that extending dimensions of polymorphism beyond HM resulted in a multi-staged solution: resolve the typing relations first, while delaying to resolve kinding relations, and then resolve the delayed kinding relations. Our work demonstrates that logic programing is effective for prototyping polymorphic type systems with rich features of polymorphism, and that logic programming could have been even more effective for specifying type inference if it were equipped with better theories and tools for staged resolution of different relations at different levels.

Keywords

Hindley–Milner Functional language Type system Type inference Unification Parametric polymorphism Higher-kinded polymorphism Type constructor polymorphism Kind polymorphism Algebraic datatype Nested datatype Logic programming Prolog Delayed goals 

References

  1. 1.
    Abel, A., Matthes, R., Uustalu, T.: Generalized iteration and coiteration for higher-order nested datatypes. In: FoSSaCS 2003 (2003)Google Scholar
  2. 2.
    Ahn, K.Y.: The Nax language. Ph.D. thesis, Department of Computer Science, Portland State University, November 2014Google Scholar
  3. 3.
    Ahn, K.Y., Sheard, T.: A hierarchy of Mendler-style recursion combinators. In: ICFP 2011. ACM (2011)Google Scholar
  4. 4.
    Ahn, K.Y., Sheard, T., Fiore, M., Pitts, A.M.: System Fi: a higher-order polymorphic lambda calculus with erasable term indices. In: TLCA 2013 (2013)Google Scholar
  5. 5.
    Alves, S., Florido, M.: Type inference using Constraint Handling Rules. In: WFLP 2001, vol. 64 of Electronic Notes in TCS, pp. 56–72. Elsevier (2002)Google Scholar
  6. 6.
    Ancona, D., Lagorio, G.: Coinductive type systems for object-oriented languages. In: Drossopoulou, S. (ed.) ECOOP 2009. LNCS, vol. 5653, pp. 2–26. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  7. 7.
    Barendregt, H.: Introduction to generalized type systems. J. Funct. Program. 1(2), 125–154 (1991)MathSciNetMATHGoogle Scholar
  8. 8.
    Bird, R., Meertens, L.: Nested datatypes. In: MPC: 4th International Conference on Mathematics of Program Construction (1998)Google Scholar
  9. 9.
    Byrd, W.E.: Relational programming in miniKanren: techniques, applications,and implementations. Ph.D. thesis, Indiana University (2009)Google Scholar
  10. 10.
    Cheney, J., Urban, C.: \(\alpha \)Prolog: A logic programming language with names, binding, and \(\alpha \)-equivalence. In: Demoen, B., Lifschitz, V. (eds.) ICLP 2004. LNCS, vol. 3132, pp. 269–283. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  11. 11.
    Csorba, J., Zombori, Z., Szeredi, P.: Pros and cons of using CHR for type inference. In: CHR 2012, KU Leuven, Deptarment of CS, Tech-report CW 624 (2012)Google Scholar
  12. 12.
    Despeyroux, T.: Executable specification of static semantics. In: MacQueen, D.B., Plotkin, G., Kahn, G. (eds.) Semantics of Data Types 1984. LNCS, vol. 173, pp. 215–233. Springer, Heidelberg (1984)CrossRefGoogle Scholar
  13. 13.
    Dubois, C.: Proving ML type soundness within Coq. In: Aagaard, M.D., Harrison, J. (eds.) TPHOLs 2000. LNCS, vol. 1869, pp. 126–144. Springer, Heidelberg (2000)CrossRefGoogle Scholar
  14. 14.
    Friedman, D.P., Byrd, W.E., Kiselyov, O.: The Reasoned Schemer. MIT Press, Cambridge (2005). ISBN 978-0-262-56214-0Google Scholar
  15. 15.
    Fu, P., Komendantskaya, E.: A type theoretic approach to structural resolution. In: Pre-Proceedings of LOPSTR 2015 (2015)Google Scholar
  16. 16.
    Gaster, B.R., Jones, M.P.: A polymorphic type system for extensible records and variants. Technical report (1996)Google Scholar
  17. 17.
    J.-Y. Girard. Interprétation fonctionelle et élimination des coupures de l’arithmétique d’ordre supérieur. Ph.D. thesis, Université Paris VII (1972)Google Scholar
  18. 18.
    Hemann, J., Friedman, D.P.: \(\mu \)Kanren: A minimal functional core for relational programming. In: Scheme 2013 (2013)Google Scholar
  19. 19.
    Johann, P., Komendantskaya, E., Komendantskiy, V.: Structural resolution for logic programming. In: Techincal Communications of ICLP (2015)Google Scholar
  20. 20.
    Jones, M.P.: Typing Haskell in Haskell. In: Haskell 1999, October 1999Google Scholar
  21. 21.
    Matthes, R.: Extensions of System F by Iteration and Primitive Recursion on Monotone Inductive Types. Ph.D. thesis, Ludwig-Maximilians University (1998)Google Scholar
  22. 22.
    McBride, C.: First-order unification by structural recursion. J. Func. Program. 13, 1061–1075 (2003). ISSN 1469–7653MathSciNetCrossRefMATHGoogle Scholar
  23. 23.
    Mitchell, D.J., Nadathur, G.: System description: teyjus - a compiler and abstract machine based implementation of \(\lambda \)prolog. In: Ganzinger, H. (ed.) CADE 1999. LNCS (LNAI), vol. 1632, pp. 287–291. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  24. 24.
    Odersky, M., Sulzmann, M., Wehr, M.: Type inference with constrained types. Theor. Pract. Object Syst. 5(1), 35–55 (1999). ISSN 1074–3227CrossRefGoogle Scholar
  25. 25.
    Pereira, F.C.N., Warren, D.H.D.: Definite clause grammars for language analysis. Artif. Intell. 13, 231–278 (1980)MathSciNetCrossRefMATHGoogle Scholar
  26. 26.
    Poole, D., Mackworth, A.K.: Artificial Intelligence - Foundations of Computational Agents. Cambridge University Press, Cambridge (2010)CrossRefMATHGoogle Scholar
  27. 27.
    Russo, C.V., Vytiniotis, D.: Qml: explicit first-class polymorphism for ml. In: ML 2009, pp. 3–14. ACM, New York (2009)Google Scholar
  28. 28.
    Schrijvers, T., Costa, V.S., Wielemaker, J., Demoen, B.: Towards typed prolog. In: Garcia de la Banda, M., Pontelli, E. (eds.) ICLP 2008. LNCS, vol. 5366, pp. 693–697. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  29. 29.
    Schrijvers, T., Demoen, B., Desouter, B., Wielemaker, J.: Delimited continuations for prolog. In: Proceedings of ICLP 2013 TPLP (2013)Google Scholar
  30. 30.
    Scott, D.S.: A type-theoretic alternative to CUCH ISWIM OWHY. Manuscript (1969)Google Scholar
  31. 31.
    SWI-Prolog team. SWI-Prolog reference manual (section 4.2) (2005)Google Scholar
  32. 32.
    Urban, C., Nipkow, T.: Nominal verification of algorithm W. In: From Semantics to Computer Science, pp. 363–382. Cambridge University Press (2009)Google Scholar
  33. 33.
    Vene, V.: Categorical Programming with Inductive and Coinductive Types. Ph.D. thesis, Department of Computer Science, University of Tartu, August 2000Google Scholar
  34. 34.
    Yorgey, B.A., Weirich, S., Cretin, J., Peyton Jones, S., Vytiniotis, D., Magalhães, J.P.: Giving Haskell a promotion. In: TLDI 2012. ACM (2012)Google Scholar

Copyright information

© Springer International Publishing Switzerland 2016

Authors and Affiliations

  1. 1.Portland State UniversityPortlandUSA
  2. 2.Chalmers University of TechnologyGothenburgSweden

Personalised recommendations