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.
Part of this work was done when the author was at Oak Ridge National Laboratory, Oak Ridge TN, USA, managed by UT-Battelle, LLC for the U.S. Department of Energy under contract number DE-AC05-00OR22725.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
Barwise, J., Moss, L.: Vicious Circles. CSLI (1996)
Beaven, M., Stansifer, R.: Explaining type errors in polymorphic languages. ACM Letters on Programming Languages (1994)
Cardelli, L.: Basic polymorphic typechecking. Science of Computer Programming 8, 147–172 (1987)
Curry, H.B., Feys, R.: Combinatory Logic, vol. 1. North-Holland, Amsterdam (1958)
Choppella, V., Haynes, C.T.: Source-tracking Unification. In: Baader, F. (ed.) CADE 2003. LNCS (LNAI), vol. 2741, pp. 458–472. Springer, Heidelberg (2003)
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)
Choppella, V.: Unification Source-tracking with Application to Diagnosis of Type Inference. PhD thesis, Indiana University, IUCS Tech Report TR566 (August 2002)
Choppella, V.: An implementation of algorithm of WE (October 2003), http://www.iiitmk.ac.in/hyplan/choppell/WE.tar.gz
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)
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)
Cox, P.T.: On determining the causes of non-unifiability. Journal of Logic Programming 4(1), 33–58 (1987)
Damas, L.: Type assignment in Programming Languages. PhD thesis, University of Edinburgh (April 1985)
Duggan, D., Bent, F.: Explaining type inference. Science of Computer Programming 27(1), 37–83 (1996)
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)
Henglein, F.: Type inference with polymorphic recursion. ACM Transactions on Programming Languages and Systems 15(2), 253–289 (1993)
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)
Hindley, R.: The principal type-scheme of an object in combinatory logic. Transactions of the American Mathematical Society 146, 29–60 (1969)
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)
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)
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)
Le Chenadec, P.: On the logic of unification. Journal of Symbolic computation 8(1), 141–199 (1989)
Lee, O., Yi, K.: Proofs about a folklore let-polymorphic type inference algorithm. ACM Transactions on Programming Languages 20(4), 707–723 (1998)
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)
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)
Milner, R.: A theory of type polymorphism in programming. Journal of Computer and System Sciences 17, 348–375 (1978)
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)
Milner, R., Tofte, M., Harper, R.: The Definition of Standard ML. MIT Press, Cambridge (1990)
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)
Peyton-Jones, S., Hughes, J. (eds.): Haskell 98: A non-strict, purely functional language (February 1999), http://www.haskell.org/onlinereport
Paterson, M., Wegman, M.: Linear unification. Journal of Computer and System Sciences 16(2), 158–167 (1978)
Rémy, D.: Extension of ML type system with a sorted equation theory on types. Technical Report 1766, INRIA (October 1992)
Walz, J.A.: Extending Attribute Grammars and Type Inference Algorithms. PhD thesis, Cornell University, TR 89-968 (February 1989)
Wand, M.: Finding the source of type errors. In: 13th Annual ACM Symp. on Principles of Prog. Languages, January 1986, pp. 38–43 (1986)
Wand, M.: A simple algorithm and proof for type inference. Fundamenta Informaticae 10, 115–122 (1987)
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)
Yang, J., Michaelson, G.: A visualisation of polymorphic type checking. Journal of Functional Programming 10(1), 57–75 (2000)
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)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2004 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Choppella, V. (2004). Polymorphic Type Reconstruction Using Type Equations. In: Trinder, P., Michaelson, G.J., Peña, R. (eds) Implementation of Functional Languages. IFL 2003. Lecture Notes in Computer Science, vol 3145. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-27861-0_4
Download citation
DOI: https://doi.org/10.1007/978-3-540-27861-0_4
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-23727-3
Online ISBN: 978-3-540-27861-0
eBook Packages: Computer ScienceComputer Science (R0)