c2hs - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Vincent L

I'd like to try c2hs. I'm looking at the doc here : https://github.com/haskell/c2hs where they say it's possible to install it via cabal. However how can I run executable from cabal ? I'm used to use cabal to download and build dependencies, but I never ran tool with it.

c2hs is a pre-processor for Haskell FFI bindings to C libraries - haskell/c2hs
Torsten Schmits

cabal will automatically run c2hs for files with the extension .chs, you just have to add c2hs to the build-tool-depends

Vincent L

but what is chs file ?

Torsten Schmits

it's what c2hs consumes!

Vincent L

yes but what is it supposed to contain ? I suspect it's not a C header

Torsten Schmits

it's all explained here:

https://github.com/haskell/c2hs/wiki/Implementation-of-Haskell-Binding-Modules

c2hs is a pre-processor for Haskell FFI bindings to C libraries - haskell/c2hs
Vincent L

was looking at the "usage of c2hs" page

Torsten Schmits

the doc is pretty hard to read in general imo

Torsten Schmits

just ask here if you don't get something

Torsten Schmits

it definitely helps to know how CFFI works in general

Vincent L

I gave it a try, and also tried hsc2hs, I'm a bit confused by the purpose of both tools

Vincent L

they seem to provide the same functionnalities with slighlty different syntax

Vincent L

on top of that I looked at inline-c, it looks promising too, but handling C struct requires to use "manual" code if I understand inline-c-nag correctly

Vincent L

by the way is it possible to encode a c struct outside of a IO() monad ?

Vincent L

peek and poke seems to be IO only