Chapter 10. Foreign Function Interface
In the previous chapter, we learned how the GHC code generator works and how to dig deeper into the compiler pipeline when necessary. In this chapter we will learn to interface with C from Haskell, and with Haskell functions from C. The foreign function interface (FFI) is part of the Haskell language report. The tooling for binding into shared libraries and also for compiling Haskell into shared libraries is quite mature. In this chapter we will cover the fundamentals of the FFI: importing and exporting functions, marshalling data, invoking the Haskell runtime from C, and building shared libraries with Haskell.
One of Haskell's strongest points compared to many languages is in fact the FFI: it's relatively ...
Get Haskell High Performance Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.