Abstract
The popularity of statically typed programming languages compiling to JavaScript shows that there exists a fringe of the programmer population interested in leveraging the benefits of static typing to write Web applications. To be of any use, these languages need to statically expose the Web browser dynamically typed native API, which seems to be a contradiction in terms. Indeed, we observe that existing statically typed languages compiling to JavaScript expose the browser API in ways that either are not type safe, or when they are, typically over constrain the programmers. This article presents new ways to encode the challenging parts of the Web browser API in static type systems such that both type safety and expressive power are preserved. Our first encoding relies on type parameters and can be implemented in most mainstream languages but drags phantom types up to the usage sites. The second encoding does not suffer from this inconvenience but requires the support of dependent types in the language.
Keywords
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.
Download to read the full chapter text
Chapter PDF
Similar content being viewed by others
References
Brady, E.: Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of Functional Programming 23(05), 552–593 (2013)
Cannasse, N.: Using haxe. The Essential Guide to Open Source Flash Development, 227–244 (2008)
Chugh, R., Herman, D., Jhala, R.: Dependent types for javascript. SIGPLAN Not. 47(10), 587–606 (2012)
W3C-World Wide Web Consortium et al.: Document object model (dom) level 3 core specification. W3C recommendation (2004)
Cremet, V., Garillot, F., Lenglet, S., Odersky, M.: A core calculus for scala type checking. In: Královič, R., Urzyczyn, P. (eds.) MFCS 2006. LNCS, vol. 4162, pp. 1–23. Springer, Heidelberg (2006)
Czaplicki, E.: Elm: Concurrent frp for functional guis (2012)
Doeraene, S.: Scala.js: Type-Directed Interoperability with Dynamically Typed Languages. Technical report (2013)
Fenton, S.: Typescript for javascript programmers (2012)
Griffith, R.: The dart programming language for non-programmers-overview (2011)
Kereki, F.: Web 2.0 development with the Google web toolkit. Linux J., 2009(178) (February 2009)
Kossakowski, G., Amin, N., Rompf, T., Odersky, M.: JavaScript as an embedded DSL. In: Noble, J. (ed.) ECOOP 2012. LNCS, vol. 7313, pp. 409–434. Springer, Heidelberg (2012)
Leijen, D., Meijer, E.: Domain specific embedded compilers. ACM SIGPLAN Notices 35, 109–122 (1999)
Lerner, B.S., Elberty, L., Li, J., Krishnamurthi, S.: Combining Form and Function: Static Types for JQuery Programs. In: Castagna, G. (ed.) ECOOP 2013. LNCS, vol. 7920, pp. 79–103. Springer, Heidelberg (2013)
Liberty, J., Betts, P.: Reactive extensions for javascript. In: Programming Reactive Extensions and LINQ, pp. 111–124. Springer (2011)
Meijer, E., Drayton, P.: Static typing where possible, dynamic typing when needed: The end of the cold war between programming languages
Odersky, M., Cremet, V., Röckl, C., Zenger, M.: A nominal theory of objects with dependent types. In: Cardelli, L. (ed.) ECOOP 2003. LNCS, vol. 2743, pp. 201–224. Springer, Heidelberg (2003)
Odersky, M., Zenger, M.: Scalable component abstractions. ACM SIGPLAN Notices 40, 41–57 (2005)
Raggett, D., Le Hors, A., Jacobs, I., et al.: Html 4.01 specification. W3C Recommendation 24 (1999)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2014 Springer International Publishing Switzerland
About this paper
Cite this paper
Richard-Foy, J., Barais, O., Jézéquel, JM. (2014). Using Path-Dependent Types to Build Type Safe JavaScript Foreign Function Interfaces. In: Casteleyn, S., Rossi, G., Winckler, M. (eds) Web Engineering. ICWE 2014. Lecture Notes in Computer Science, vol 8541. Springer, Cham. https://doi.org/10.1007/978-3-319-08245-5_18
Download citation
DOI: https://doi.org/10.1007/978-3-319-08245-5_18
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-08244-8
Online ISBN: 978-3-319-08245-5
eBook Packages: Computer ScienceComputer Science (R0)