Hostname: page-component-78c5997874-dh8gc Total loading time: 0 Render date: 2024-11-06T05:17:20.014Z Has data issue: false hasContentIssue false

F-ing modules

Published online by Cambridge University Press:  19 November 2014

ANDREAS ROSSBERG
Affiliation:
Google, Dienerstr. 12, 80331 Munich, Germany (e-mail: [email protected])
CLAUDIO RUSSO
Affiliation:
Microsoft Research 21 Station Road, Cambridge CB1 2FB, United Kingdom (e-mail: [email protected])
DEREK DREYER
Affiliation:
Max Planck Institute for Software Systems (MPI-SWS), 66123 Saarbrücken, Germany (e-mail: [email protected])
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.

ML modules are a powerful language mechanism for decomposing programs into reusable components. Unfortunately, they also have a reputation for being “complex” and requiring fancy type theory that is mostly opaque to non-experts. While this reputation is certainly understandable, given the many non-standard methodologies that have been developed in the process of studying modules, we aim here to demonstrate that it is undeserved. To do so, we present a novel formalization of ML modules, which defines their semantics directly by a compositional “elaboration” translation into plain System Fω (the higher-order polymorphic λ-calculus). To demonstrate the scalability of our “F-ing” semantics, we use it to define a representative, higher-order ML-style module language, encompassing all the major features of existing ML module dialects (except for recursive modules). We thereby show that ML modules are merely a particular mode of use of System Fω.

To streamline the exposition, we present the semantics of our module language in stages. We begin by defining a subset of the language supporting a Standard ML-like language with second-class modules and generative functors. We then extend this sublanguage with the ability to package modules as first-class values (a very simple extension, as it turns out) and OCaml-style applicative functors (somewhat harder). Unlike previous work combining both generative and applicative functors, we do not require two distinct forms of functor or signature sealing. Instead, whether a functor is applicative or not depends only on the computational purity of its body. In fact, we argue that applicative/generative is rather incidental terminology for pure versus impure functors. This approach results in a semantics that we feel is simpler and more natural than previous accounts, and moreover prohibits breaches of abstraction safety that were possible under them.

Type
Articles
Copyright
Copyright © Cambridge University Press 2014 

References

Ahmed, A., Dreyer, D. & Rossberg, A. (2009) State-dependent representation independence. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 350353.Google Scholar
Atkey, R. (2012) Relational parametricity for higher kinds. EACSL Annual Conference on Computer Science Logic, pp. 4661.Google Scholar
Aydemir, B., Charguéraud, A., Pierce, B. C., Pollack, R.. & Weirich, S.. (2008) Engineering formal metatheory. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 315.Google Scholar
Aydemir, B., Weirich, S. & Zdancewic, S.. (2009) Abstracting syntax. Technical report.Google Scholar
Biswas, S. K. (1995) Higher-order functors with transparent signatures. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 154–163.Google Scholar
Cardelli, L. & Leroy, X.. (1990) Abstract types and the dot notation. In Programming Concepts and Methods, IFIP State of the Art Reports. North Holland, pp. 479504.Google Scholar
Coq Development Team. (2007) The Coq proof assistant reference manual. INRIA. Available at: http://coq.inria.fr/+.Google Scholar
Dreyer, D. (2005) Understanding and Evolving the ML Module System. Ph.D. thesis, Carnegie Mellon University.Google Scholar
Dreyer, D. (2007a) Recursive type generativity. J. Funct. Program. 17 (4–5), 433471.Google Scholar
Dreyer, D. (2007b) A type system for recursive modules. In ACM SIGPLAN International Conference on Functional Programming, 289302.CrossRefGoogle Scholar
Dreyer, D. & Blume, M.. (2007) Principal type schemes for modular programs. In European Symposium on Programming, pp. 441457.Google Scholar
Dreyer, D., Crary, K. & Harper, R.. (2002) Moscow ML's higher-order modules are unsound. Posting to Types forum, 17 September.Google Scholar
Dreyer, D., Crary, K. & Harper, R.. (2003) A type system for higher-order modules. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 236249.Google Scholar
Elsman, M. (1999) Program Modules, Separate Compilation, and Intermodule Optimisation. Ph.D. thesis, University of Copenhagen.Google Scholar
Geuvers, H. (1992) The Church-Rosser property for βη-reduction in typed λ-calculi. In IEEE Symposium on Logic in Computer Science, 453460.Google Scholar
Ghelli, G. & Pierce, B.. (1998) Bounded existentials and minimal typing. Theor. Comput. Sci. 193 (1-2), 7596.Google Scholar
Goldfarb, W.D. (1981) The undecidability of the second-order unification problem. Theor. Comput. Sci. 13, 225230.Google Scholar
Harper, R. (2012) Programming in Standard ML. Available at: http://www.cs.cmu.edu/~rwh/smlbook/.Google Scholar
Harper, R. & Lillibridge, M.. (1994) A type-theoretic approach to higher-order modules with sharing. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 123137.CrossRefGoogle Scholar
Harper, R. & Mitchell, J. C. (1993) On the type structure of Standard ML. ACM Trans. Program. Lang. Syst. 15 (2), 211252.Google Scholar
Harper, R., Mitchell, J. C. & Moggi, E.. (1990) Higher-order modules and the phase distinction. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 341354.Google Scholar
Harper, R. & Pierce, B. C. (2005) Design considerations for ML-style module systems. In Advanced Topics in Types and Programming Languages, Pierce, B. C. (ed), chapter 8, MIT.Google Scholar
Harper, R. & Stone, C.. (2000) A type-theoretic interpretation of Standard ML. In Proof, Language, and Interaction: Essays in Honor of Robin Milner, MIT, 341388.Google Scholar
Jones, M. P. (1996) Using parameterized signatures to express modular structure. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 68–78.CrossRefGoogle Scholar
Kuan, G. & MacQueen, D.. (2010) Engineering higher-order modules in SML/NJ. In International Symposium on the Implementation and Application of Functional Languages. Lecture Notes in Computer Science, Volume 6041, 2010, pp 218235.Google Scholar
Launchbury, J. & Peyton Jones, S. L. (1995) State in Haskell. LISP Symbol. Comput. 8 (4), 293341.CrossRefGoogle Scholar
Lee, D. K., Crary, K. & Harper, R. (2007) Towards a mechanized metatheory of Standard ML. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 173184.Google Scholar
Leifer, J., Peskine, G., Sewell, P. & Wansbrough, K. (2003) Global abstraction-safe marshalling with hash types. In ACM SIGPLAN International Conference on Functional Programming, 8798.CrossRefGoogle Scholar
Leroy, X. (1994) Manifest types, modules, and separate compilation. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 109122.Google Scholar
Leroy, X. (1995) Applicative functors and fully transparent higher-order modules. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 142153.Google Scholar
Leroy, X. (1996) A syntactic theory of type generativity and sharing. J. Funct. Program. 6 (5), 667698.CrossRefGoogle Scholar
Leroy, X. (2000) A modular module system. J. Funct. Program. 10 (3), 269303.Google Scholar
Lillibridge, M. (1997) Translucent Sums: A Foundation for Higher-Order Module Systems. Ph.D. thesis, Carnegie Mellon University.Google Scholar
MacQueen, D. B. (1986) Using dependent types to express modular structure. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 277286.Google Scholar
MacQueen, D. B. & Tofte, M. (1994) A semantics for higher-order functors. In In European Symposium on Programming, 409423.Google Scholar
Milner, R., Tofte, M. & Harper, R. (1990) The Definition of Standard ML, MIT.Google Scholar
Milner, R., Tofte, M., Harper, R. & MacQueen, D. (1997) The Definition of Standard ML (revised), MIT.CrossRefGoogle Scholar
Mitchell, J. C. & Plotkin, G. D. (1988) Abstract types have existential type. ACM Trans. Program. Lang. Syst. 10 (3), 470502.Google Scholar
Montagu, B. & Rémy, D. (2009) Modeling abstract types in modules with open existential types. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 354365.Google Scholar
Paulson, L. C. (1996) ML for the Working Programmer, 2nd ed.Cambridge University Press.Google Scholar
Peyton Jones, S. (2003) Wearing the hair shirt: a retrospective on Haskell. Invited talk, ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. Available at: http://research.microsoft.com/~simonpj.Google Scholar
Romanenko, S., Russo, C. V. & Sestoft, P. (2000) Moscow ML Version 2.0. Available at: http://www.dina.kvl.dk/~sestoft/mosml.Google Scholar
Rossberg, A. (1999) Undecidability of OCaml type checking. Posting to Caml mailing list, 13 July.Google Scholar
Rossberg, A. & Dreyer, D. (2013) Mixin' up the ML module system. ACM Trans. Lang. Syst. 35 (1), Article 2, 2:1–2:84.Google Scholar
Rossberg, A., Le Botlan, D., Tack, G. & Smolka, G. (2004) Alice through the looking glass. In Trends in Functional Programming, 7985.Google Scholar
Rossberg, A., Russo, C. V. & Dreyer, D. (2010) F-ing modules. In ACM SIGPLAN Workshop on Types in Language Design and Implementation, 89102.Google Scholar
Russo, C. V. (1998) Types for Modules. Ph.D. thesis, LFCS, University of Edinburgh.Google Scholar
Russo, C. V. (1999) Non-dependent types for Standard ML modules. In International Conference on Principles and Practice of Declarative Programming, 8097.Google Scholar
Russo, C. V. (2000) First-class structures for Standard ML. Nord. J. Comput. 7 (4), 348374.Google Scholar
Russo, C. V. (2003) Types for modules. In Electronic Notes in Theoretical Computer Science, 60, 3421.Google Scholar
Sewell, P., Leifer, J. J., Wansbrough, K., Zappa Nardelli, F., Allen.-Williams, M., Habouzit, P. & Vafeiadis, V. (2007) Acute: High-level programming language design for distributed computation. J. Funct. Program. 17 (4–5), 547612.Google Scholar
Shan, C.-C. (2004) Higher-order modules in System Fω and Haskell. Technical Report. Available at: http://www.cs.rutgers.edu/~ccshan/xlate/xlate.pdf.Google Scholar
Shao, Z. (1999) Transparent modules with fully syntactic signatures. In ACM SIGPLAN International Conference on Functional Programming, 220232.Google Scholar
Shields, M. & Peyton Jones, S. (2002) First-class modules for Haskell. In International Workshop on Foundations of Object-Oriented Language, pp. 2840.Google Scholar
SML/NJ Development Team (1993) Standard ML of New Jersey user's guide. 0.93 ed., AT&T Bell Laboratories.Google Scholar
Stone, C. A. & Harper, R. (2006) Extensional equivalence and singleton types. ACM Trans. Comput. Log. 7 (4), 676722.Google Scholar
Sulzmann, M., Chakravarty, M. M. T., Peyton Jones, S. & Donnelly, K. (2007) System F with type equality coercions. In ACM SIGPLAN Workshop on Types in Language Design and Implementation, 5366.Google Scholar
Torgersen, M., Ernst, E. & Hanser, C. P. (2005) Wild FJ. In International Workshop on Foundations of Object-Oriented Languages, 115.Google Scholar
Wright, A. (1995) Simple imperative polymorphism. In LISP and Symbolic Computation, pp. 343356.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.