Skip to main content

Declarative Foreign Function Binding Through Generic Programming

  • Conference paper
  • First Online:
Functional and Logic Programming (FLOPS 2016)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 9613))

Included in the following conference series:

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 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

  1. 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)

    Google Scholar 

  2. Beazley, D.M.: SWIG: An easy to use tool for integrating scripting languages with C and C++. In: USENIX Tcl/Tk Workshop (1996)

    Google Scholar 

  3. Benke, M., Dybjer, P., Jansson, P.: Universes for generic programs and proofs in dependent type theory. Nord. J. Comput. 10(4), 265–289 (2003)

    MathSciNet  MATH  Google Scholar 

  4. Blume, M.: No-longer-foreign: Teaching an ML compiler to speak C “natively”. Electron. Notes Theoret. Comput. Sci. 59(1), 36–52 (2001)

    Article  Google Scholar 

  5. 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)

    Article  MathSciNet  MATH  Google Scholar 

  6. Cheney, J., Hinze, R.: A lightweight implementation of generics and dynamics. In: Haskell 2002, pp. 90–104. ACM, New York (2002)

    Google Scholar 

  7. Danvy, O., Malmkjær, K., Palsberg, J.: Eta-expansion does the trick. ACM Trans. Program. Lang. Syst. 18(6), 730–751 (1996)

    Article  Google Scholar 

  8. Furr, M., Foster, J.S.: Checking type safety of foreign function calls. In: PLDI 2005, pp. 62–72. ACM, New York (2005)

    Google Scholar 

  9. 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)

    Chapter  Google Scholar 

  10. Hinze, R.: Generics for the masses. J. Funct. Program. 16(4–5), 451–483 (2006)

    Article  MathSciNet  MATH  Google Scholar 

  11. Karvonen, V.A.J.: Generics for the working ML’er. In: ML 2007. ACM (2007)

    Google Scholar 

  12. Kondoh, G., Onodera, T.: Finding bugs in java native interface programs. In: ISSTA 2008, pp. 109–118. ACM (2008)

    Google Scholar 

  13. 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

    Google Scholar 

  14. 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)

    Google Scholar 

  15. Nordström, B., Petersson, K., Smith, J.M.: Programming in Martin-Löf Type Theory: An Introduction. Clarendon, New York (1990)

    MATH  Google Scholar 

  16. Vouillon, J.: Lwt: A cooperative thread library. In: ML 2008. ACM (2008)

    Google Scholar 

  17. Yang, Z.: Encoding types in ML-like languages. In: ICFP 1998. ACM (1998)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Jeremy Yallop .

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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)

Publish with us

Policies and ethics