Abstract
Foreign function interfaces are typically organised monolithically, tying together the specification of each foreign function with the mechanism used to make the function available in the host language. This leads to inflexible systems, where switching from one binding mechanism to another (say from dynamic binding to static code generation) often requires changing tools and rewriting large portions of code.
In contrast, approaching the design of a foreign function interface as a generic programming problem allows foreign function specifications to be written declaratively, with easy switching between a wide variety of binding mechanisms — static and dynamic, synchronous and asynchronous, etc. — with no changes to the specifications.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
There are no calls to protect local variables from the GC because the code generator can statically determine that the GC cannot run during the execution of this function. However, it is not generally possible to determine whether the bound C function can call back into OCaml, and so the user must inform the code generator if such callbacks may occur by passing a flag to .
References
Altenkirch, T., McBride, C.: Generic programming within dependently typed programming. In: Proceedings of the IFIP TC2/WG2.1 Working Conference on Generic Programming, pp. 1–20 (2003)
Beazley, D.M.: SWIG: An easy to use tool for integrating scripting languages with C and C++. In: USENIX Tcl/Tk Workshop (1996)
Benke, M., Dybjer, P., Jansson, P.: Universes for generic programs and proofs in dependent type theory. Nord. J. Comput. 10(4), 265–289 (2003)
Blume, M.: No-longer-foreign: Teaching an ML compiler to speak C “natively”. Electron. Notes Theoret. Comput. Sci. 59(1), 36–52 (2001)
Carette, J., Kiselyov, O., Shan, C.: Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program. 19(5), 509–543 (2009)
Cheney, J., Hinze, R.: A lightweight implementation of generics and dynamics. In: Haskell 2002, pp. 90–104. ACM, New York (2002)
Danvy, O., Malmkjær, K., Palsberg, J.: Eta-expansion does the trick. ACM Trans. Program. Lang. Syst. 18(6), 730–751 (1996)
Furr, M., Foster, J.S.: Checking type safety of foreign function calls. In: PLDI 2005, pp. 62–72. ACM, New York (2005)
Gibbons, J.: Datatype-generic programming. In: Backhouse, R., Gibbons, J., Hinze, R., Jeuring, J. (eds.) SSDGP 2006. LNCS, vol. 4719, pp. 1–71. Springer, Heidelberg (2007)
Hinze, R.: Generics for the masses. J. Funct. Program. 16(4–5), 451–483 (2006)
Karvonen, V.A.J.: Generics for the working ML’er. In: ML 2007. ACM (2007)
Kondoh, G., Onodera, T.: Finding bugs in java native interface programs. In: ISSTA 2008, pp. 109–118. ACM (2008)
Leroy, X., Doligez, D., Frisch, A., Garrigue, J., Rémy, D., Vouillon, J.: The OCaml system (release 3.12): Documentation and user’s manual. In: INRIA, July 2011
Li, S., Tan, G.: Finding reference-counting errors in python/C programs with affine analysis. In: Jones, R. (ed.) ECOOP 2014. LNCS, vol. 8586, pp. 80–104. Springer, Heidelberg (2014)
Nordström, B., Petersson, K., Smith, J.M.: Programming in Martin-Löf Type Theory: An Introduction. Clarendon, New York (1990)
Vouillon, J.: Lwt: A cooperative thread library. In: ML 2008. ACM (2008)
Yang, Z.: Encoding types in ML-like languages. In: ICFP 1998. ACM (1998)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2016 Springer International Publishing Switzerland
About this paper
Cite this paper
Yallop, J., Sheets, D., Madhavapeddy, A. (2016). Declarative Foreign Function Binding Through Generic Programming. In: Kiselyov, O., King, A. (eds) Functional and Logic Programming. FLOPS 2016. Lecture Notes in Computer Science(), vol 9613. Springer, Cham. https://doi.org/10.1007/978-3-319-29604-3_13
Download citation
DOI: https://doi.org/10.1007/978-3-319-29604-3_13
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-29603-6
Online ISBN: 978-3-319-29604-3
eBook Packages: Computer ScienceComputer Science (R0)