This part six of a six part introduction to c2hs. We finally talk about what ostensibly is the point of c2hs: calling C functions from Haskell. c2hs, due to its knowledge of the C headers, can already do the work for generating FFI imports. The call hook simply tells c2hs to generate the FFI import, […]
This part five of a six part introduction to c2hs. Today, we explain how to marshal data to and from C structures. An important note. There is a difference between struct foo and foo; c2hs only considers the latter a type, so you may need to add some typedefs of the form typedef struct foo […]
This is part four of a six part tutorial series on c2hs. Today we discuss the simple things in c2hs, namely the type, enum, pointer, import and context directives. Prior art. All of the directives c2hs supports are tersely described in the “tutorial” page (which would perhaps be more accurately described as a “reference manual”, […]
This is part three of a six part tutorial series on c2hs. Today, we take a step back from the nitty gritty details of FFI bindings and talk about more general design principles for your library. On the one hand, writing an FFI binding can little more than churning out the glue code to let […]
This part two of a six part introduction to c2hs. Today, we discuss getting the damn thing to compile in the first place. Reader prerequisites. You should know how to write, configure and build a vanilla Cabal file for pure Haskell. Fortunately, with cabal init, this is easier than ever. I'll talk about how to […]
This post is part of what I hope will be a multi-part tutorial/cookbook series on using c2hs (Hackage). The Haskell Preprocessor Hierarchy (this post) Setting up Cabal, the FFI and c2hs Principles of FFI API design First steps in c2hs Marshalling with get an set Call and fun: marshalling redux What's c2hs? c2hs is a […]