# Path resolution for nested recursive modules

- 78 Downloads

## Abstract

The ML module system facilitates the modular development of large programs, through decomposition, abstraction and reuse. To increase its flexibility, a lot of work has been devoted to extending it with recursion, which is currently prohibited. The introduction of recursion adds expressivity to the module system. However it also creates problems that a non-recursive module system does not have.

In this paper, we address one such problem, namely resolution of path references. Paths are how one refers to nested modules in ML. Without recursion, well-typedness guarantees termination of path resolution, in other words, we can statically determine the module that a path refers to. This does not always hold with recursive module extensions, since the module system then can encode a lambda-calculus with recursion, whose termination is undecidable regardless of well-typedness. We formalize this problem of path resolution by means of a rewrite system on paths and prove that the problem is undecidable even without higher-order functors, via an encoding of the Turing machine into a calculus with just recursive modules, first-order functors, and nesting. Motivated by this result, we introduce a further restriction on first-order functors, limiting polymorphism on functor parameters by requiring signatures for functor parameters to be non-recursive, and show that this restriction is decidable and admits terminating path resolution.

## Keywords

The ML module system Recursive modules Ground term rewriting Decidability Termination## Notes

### Acknowledgements

We thank the referees for helping us improve this article, and Olivier Danvy for his editorial support. James Chapman made helpful comments on the final version.

K. Nakata’s research was supported by the European Regional Development Fund (ERDF) through the Estonian Centre of Excellence in Computer Science (EXCS), the Estonian Ministry of Education and Research target-financed research theme no. 0140007s12, and the Estonian Science Foundation grant no. 9398.

## References

- 1.Boudol, G.: The recursive record semantics of objects revisited. J. Funct. Program.
**14**, 263–315 (2004) MathSciNetMATHCrossRefGoogle Scholar - 2.Crary, K., Harper, R., Puri, S.: What is a recursive module? In: ACM SIGPLAN Conference on Programming Language Design and Implementation, pp. 50–63 (1999) Google Scholar
- 3.Cremet, V., Garillot, F., Lenglet, S., Odersky, M.: A core calculus for Scala type checking. In: Int. Symposium on Mathematical Foundations of Computer Science (2006) Google Scholar
- 4.Dauchet, M., Tison, S.: The theory of ground rewrite systems is decidable. In: IEEE Symposium on Logic in Computer Science (1990) Google Scholar
- 5.Dreyer, D.: A type system for well-founded recursion. In: ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (2004) Google Scholar
- 6.Dreyer, D.: Recursive type generativity. In: ACM SIGPLAN International Conference on Functional Programming (2005) Google Scholar
- 7.Dreyer, D.: Post to the Caml mailing list. (2007). http://caml.inria.fr/pub/ml-archives/caml-list/2007/03/73e1ea81e35002046fdce6f14c1d8848.en.html
- 8.Dreyer, D.: A type system for recursive modules. In: ACM SIGPLAN International Conference on Functional Programming (2007) Google Scholar
- 9.Dreyer, D., Crary, K., Harper, R.: A type system for higher-order modules. In: ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 236–249 (2003) CrossRefGoogle Scholar
- 10.Dreyer, D., Rossberg, A.: Mixin’ up the ML module system. In: ACM SIGPLAN International Conference on Functional Programming, pp. 307–320 (2008) Google Scholar
- 11.Harper, R., Mitchell, J.C., Moggi, E.: Higher-order modules and the phase distinction. In: ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 341–354 (1990) Google Scholar
- 12.Hirschowitz, T., Leroy, X.: Mixin modules in a call-by-value setting. In: European Symposium on Programming. Springer LNCS, vol. 2305, pp. 6–20 (2002) Google Scholar
- 13.Hopcroft, J., Motwani, R., Ullman, J.: Introduction to Automata Theory, Languages, and Computation. Addison-Wesley, Reading (2001) MATHGoogle Scholar
- 14.Im, H., Nakata, K., Garrigue, J., Park, S.: A syntactic type system for recursive modules. In: ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, pp. 993–1012 (2011) Google Scholar
- 15.Kahn, G.: Natural semantics. In: Symposium of Theoretical Aspects of Computer Science, pp. 22–39 (1987) Google Scholar
- 16.Leroy, X.: Applicative functors and fully transparent higher-order modules. In: ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 142–153. ACM Press, New York (1995) Google Scholar
- 17.Leroy, X.: A syntactic theory of type generativity and sharing. J. Funct. Program.
**6**(5), 667–698 (1996) MathSciNetMATHCrossRefGoogle Scholar - 18.Leroy, X.: A modular module system. J. Funct. Program.
**10**(3), 269–303 (2000) MATHCrossRefGoogle Scholar - 19.Leroy, X.: A proposal for recursive modules in Objective Caml. Available at http://caml.inria.fr/pub/papers/xleroy-recursive_modules-03.pdf (2003)
- 20.Leroy, X., Doligez, D., Garrigue, J., Rémy, D., Vouillon, J.: The Objective Caml System, Release 3.11. Software and documentation available on the Web, http://caml.inria.fr/ (2008)
- 21.Milner, R., Tofte, M., Harper, R., MacQueen, D.: The Definition of Standard ML—Revised. MIT Press, Cambridge (1997) Google Scholar
- 22.Montagu, B., Rémy, D.: Modeling abstract types in modules with open existential types. In: ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 354–365 (2009) Google Scholar
- 23.Mottl, M.: OCaml bug report. http://caml.inria.fr/mantis/view.php?id=3476 (2005)
- 24.Nakata, K.: OCaml bug report. http://caml.inria.fr/mantis/view.php?id=3674. (2005)
- 25.Nakata, K., Garrigue, J.: Recursive modules for programming. In: ACM SIGPLAN International Conference on Functional Programming. ACM Press, New York (2006) Google Scholar
- 26.Nakata, K., Garrigue, J.: Path resolution for recursive nested modules is undecidable. In: Int. Workshop on Termination (WST), Paris, France (2007) Google Scholar
- 27.Nakata, K., Ito, A., Garrigue, J.: Recursive object-oriented modules. In: Int. Workshop on Foundations of Object-Oriented Languages (2005) Google Scholar
- 28.Russo, C.: First-class structures for standard ML. In: European Symposium on Programming. Springer LNCS, vol. 1782 (2000) Google Scholar
- 29.Russo, C.: Recursive structures for standard ML. In: ACM SIGPLAN International Conference on Functional Programming, pp. 50–61. ACM Press, New York (2001) Google Scholar
- 30.Russo, C.: Non-dependent types for standard ML modules. In: ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming. Springer LNCS, vol. 1702, pp. 80–97 (1999) Google Scholar
- 31.Washburn, G.A.: Scala Mailing List. http://article.gmane.org/gmane.comp.lang.scala/13573/ (2008)