Advertisement

Polymorphic Type Reconstruction Using Type Equations

  • Venkatesh Choppella
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3145)

Abstract

The W algorithm of Milner [Mil78] and its numerous variants [McA98,LY98,YTMW00] implement type reconstruction by building type substitutions. We define an algorithm W E centered around building type equations rather than substitutions. The design of W E is motivated by the belief that reasoning with substitutions is awkward. More seriously, substitutions fail to preserve the exact syntactic form of the type equations they solve. This makes analysing the source of type errors more difficult. By replacing substitution composition with unions of sets of type equations and eliminating the application of substitution to environments, we obtain an algorithm for type reconstruction that is simple and also useful for type error reconstruction. We employ a sequentiality principle for unifier composition and a constructive account of mgu-induced variable occurrence relation to design W E and prove its correctness. We introduce syntax equations as a formal syntax for progam slices. We use a simple constraint generation relation to relate syntax equations with type equations to trace program slices responsible for a type error.

Keywords

Type Equation Type Error Type Inference Type Environment Term Equation 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. [BM96]
    Barwise, J., Moss, L.: Vicious Circles. CSLI (1996)Google Scholar
  2. [BS94]
    Beaven, M., Stansifer, R.: Explaining type errors in polymorphic languages. ACM Letters on Programming Languages (1994)Google Scholar
  3. [Car87]
    Cardelli, L.: Basic polymorphic typechecking. Science of Computer Programming 8, 147–172 (1987)zbMATHCrossRefGoogle Scholar
  4. [CF58]
    Curry, H.B., Feys, R.: Combinatory Logic, vol. 1. North-Holland, Amsterdam (1958)zbMATHGoogle Scholar
  5. [CH03]
    Choppella, V., Haynes, C.T.: Source-tracking Unification. In: Baader, F. (ed.) CADE 2003. LNCS (LNAI), vol. 2741, pp. 458–472. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  6. [Chi01]
    Chitil, O.: Compositional explantion of types and debugging of type errors. In: Sixth ACM SIGPLAN International Conference on Functional Programming (ICFP 2001), September 2001, ACM Press, New York (2001)Google Scholar
  7. [Cho02]
    Choppella, V.: Unification Source-tracking with Application to Diagnosis of Type Inference. PhD thesis, Indiana University, IUCS Tech Report TR566 (August 2002)Google Scholar
  8. [Cho03a]
    Choppella, V.: An implementation of algorithm of WE (October 2003), http://www.iiitmk.ac.in/hyplan/choppell/WE.tar.gz
  9. [Cho03b]
    Choppella, V.: Polymorphic Type reconstruction using type equations (full version with proofs). Technical Report SP-06, Indian Institute of Information Technology and Managament, Kerala, Technopark, Thiruvananthapuram, Kerala (October 2003)Google Scholar
  10. [Cho04]
    Choppella, V.: Source-tracking Damas-Milner using unification path embeddings. Technical report, Indian Institute of Information Technology and Management, Kerala, Technopark, Thiruvananthapuram, Kerala (2004) (in preparation)Google Scholar
  11. [Cox87]
    Cox, P.T.: On determining the causes of non-unifiability. Journal of Logic Programming 4(1), 33–58 (1987)zbMATHCrossRefMathSciNetGoogle Scholar
  12. [Dam85]
    Damas, L.: Type assignment in Programming Languages. PhD thesis, University of Edinburgh (April 1985)Google Scholar
  13. [DB96]
    Duggan, D., Bent, F.: Explaining type inference. Science of Computer Programming 27(1), 37–83 (1996)zbMATHCrossRefGoogle Scholar
  14. [DM82]
    Damas, L., Milner, R.: Principal type-schemes for functional languages. In: Proc. 9th ACM Symp. on Principles of Programming Languages, January 1982, pp. 207–212 (1982)Google Scholar
  15. [Hen93]
    Henglein, F.: Type inference with polymorphic recursion. ACM Transactions on Programming Languages and Systems 15(2), 253–289 (1993)CrossRefGoogle Scholar
  16. [HHS03]
    Heeren, B., Hage, J., Doaitse Swierstra, S.: Scripting the type inference process. In: Proceedings of the eighth ACM SIGPLAN international conference on Functional programming, Uppsala, Sweden, August 2003, pp. 3–13. ACM Press, New York (2003)CrossRefGoogle Scholar
  17. [Hin69]
    Hindley, R.: The principal type-scheme of an object in combinatory logic. Transactions of the American Mathematical Society 146, 29–60 (1969)zbMATHMathSciNetGoogle Scholar
  18. [HW03]
    Haack, C., Wells, J.: Type error slicing in higher order polymorphic languages. In: Proc. of Theory and Practice of Software (TAPAS 2003), Springer, Heidelberg (2003)Google Scholar
  19. [JW86]
    Johnson, G.F., Walz, J.A.: A maximum-flow approach to anomaly isolation in unification-based incremental type inference. In: Proceedings of the 13th ACM Symposium on Programming Languages, pp. 44–57 (1986)Google Scholar
  20. [KMM91]
    Kanellakis, P.C., Mairson, H.G., Mitchell, J.C.: Unification and ML type reconstruction. In: Lassez, J.L., Plotkin, G. (eds.) Computational Logic: Essays in honor of Alan Robinson, pp. 444–478. MIT Press, Cambridge (1991)Google Scholar
  21. [LC89]
    Le Chenadec, P.: On the logic of unification. Journal of Symbolic computation 8(1), 141–199 (1989)zbMATHCrossRefMathSciNetGoogle Scholar
  22. [LY98]
    Lee, O., Yi, K.: Proofs about a folklore let-polymorphic type inference algorithm. ACM Transactions on Programming Languages 20(4), 707–723 (1998)CrossRefGoogle Scholar
  23. [McA98]
    McAdam, B.J.: On the unification of substitutions in type inference. In: Hammond, K., Davie, T., Clack, C. (eds.) IFL 1998. LNCS, vol. 1595, pp. 139–154. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  24. [McA00]
    McAdam, B.: Generalising techniques for type debugging. In: Trinder, P., Michaelson, G., Loidl, H.-W. (eds.) Trends in Functional Programming, pp. 49–57, Intellect (2000)Google Scholar
  25. [Mil78]
    Milner, R.: A theory of type polymorphism in programming. Journal of Computer and System Sciences 17, 348–375 (1978)zbMATHCrossRefMathSciNetGoogle Scholar
  26. [MMA92]
    Maruyama, H., Matsuyama, M., Araki, K.: Support tool and strategy for type error correction with polymorphic types. In: Proceedings of the Sixteenth annual international computer software and applications conference, Chicago, September 1992, pp. 287–293. IEEE, Los Alamitos (1992)CrossRefGoogle Scholar
  27. [MTH90]
    Milner, R., Tofte, M., Harper, R.: The Definition of Standard ML. MIT Press, Cambridge (1990)Google Scholar
  28. [NT03]
    Neubauer, M., Thiemann, P.: Discriminative sum types locate the source of type errors. In: Proceedings of the eighth ACM SIGPLAN international conference on Functional programming, Uppsala, Sweden, August 2003, pp. 15–26. ACM Press, New York (2003)CrossRefGoogle Scholar
  29. [PJH99]
    Peyton-Jones, S., Hughes, J. (eds.): Haskell 98: A non-strict, purely functional language (February 1999), http://www.haskell.org/onlinereport
  30. [PW78]
    Paterson, M., Wegman, M.: Linear unification. Journal of Computer and System Sciences 16(2), 158–167 (1978)zbMATHCrossRefMathSciNetGoogle Scholar
  31. [Rém92]
    Rémy, D.: Extension of ML type system with a sorted equation theory on types. Technical Report 1766, INRIA (October 1992)Google Scholar
  32. [Wal89]
    Walz, J.A.: Extending Attribute Grammars and Type Inference Algorithms. PhD thesis, Cornell University, TR 89-968 (February 1989)Google Scholar
  33. [Wan86]
    Wand, M.: Finding the source of type errors. In: 13th Annual ACM Symp. on Principles of Prog. Languages, January 1986, pp. 38–43 (1986)Google Scholar
  34. [Wan87]
    Wand, M.: A simple algorithm and proof for type inference. Fundamenta Informaticae 10, 115–122 (1987)zbMATHMathSciNetGoogle Scholar
  35. [Wel02]
    Wells, J.B.: The essence of principal typings. In: Widmayer, P., Triguero, F., Morales, R., Hennessy, M., Eidenbenz, S., Conejo, R. (eds.) ICALP 2002. LNCS, vol. 2380, p. 913. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  36. [YM00]
    Yang, J., Michaelson, G.: A visualisation of polymorphic type checking. Journal of Functional Programming 10(1), 57–75 (2000)CrossRefGoogle Scholar
  37. [YTMW00]
    Yang, J., Trinder, P., Michaelson, G., Wells, J.: Improved type error reporting. In: Proceeding of Implementation of Functional Languages, 12th International Workshop, September 2000, pp. 71–86 (2000)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2004

Authors and Affiliations

  • Venkatesh Choppella
    • 1
  1. 1.Indian Institute of Information Technology and Management KeralaThiruvananthapuram, KeralaIndia

Personalised recommendations