Questions tagged [hsc2hs]

hsc2hs is used to write Haskell interfaces to C code. The hsc2hs command can be used to automate some parts of the process of writing Haskell bindings to C code.

The hsc2hs command can be used to automate some parts of the process of writing Haskell bindings to C code. It reads an almost-Haskell source with embedded special constructs, and outputs a real Haskell file with these constructs processed, based on information taken from some C headers. The extra constructs deal with accessing C data from Haskell...

Read more here: Writing Haskell interfaces to C code: hsc2hs

The source code can be looked at here : http://git.haskell.org/packages/hsc2hs.git

(It is mirrored on github here)

19 questions
24
votes
2 answers

Difference between hsc2hs and c2hs?

What is the difference between hsc2hs and c2hs? I know what hsc2hs is a preprocessor but what does it exactly do? And c2hs can make Haskell modules from C-code, but do I need hsc2hs for this?
develhevel
  • 3,161
  • 4
  • 21
  • 27
10
votes
2 answers

How to use hsc2hs to bind to constants, functions and data structures?

i need a example how to use hsc2hs, i thought that when i write a header file like: // foo.h #define PI 3.14159 typedef struct { int i1; int i2; } foo; struct foo2 { int i1; int i2; }; int fooFkt(foo f); and then create a hsc…
develhevel
  • 3,161
  • 4
  • 21
  • 27
6
votes
1 answer

hsc2hs: Mutate a C struct with Haskell

I am trying to write a Haskell program that communicates with C (ultimately for iOS via GHC-iOS). I want it to pass a string from C to Haskell, have Haskell process it and then return some Data types from Haskell to C Structs via hsc2s. I have been…
MCH
  • 2,124
  • 1
  • 19
  • 34
6
votes
1 answer

Haskell cabal+hsc2hs

Can cabal use hsc2hs to create hs files? How? I didn't find an answer in the manuals, googling, nor in other projects (had my hopes up for gtk2hs but it turns out that it doesn't use cabal)
yairchu
  • 23,680
  • 7
  • 69
  • 109
5
votes
0 answers

hsc2hs c++ headers

I'm trying to build a Haskell executable with an FFI against some C++ sources. I have a C header (cstuff/foo.h) like this: #ifndef _FOO_H_ #define _FOO_H_ #include // Some header outside of my control with C++ constructs void…
Kritzefitz
  • 2,644
  • 1
  • 20
  • 35
5
votes
1 answer

Simulating keystrokes with Haskell on Windows

I am trying to write a Haskell program that simulates keystrokes on Windows. I tried to call keybd_event and SendInput, but neither one compiled. I can run the program with the interpreter, though. When I try to build the program when it contains…
user2917747
  • 173
  • 7
4
votes
0 answers

Using stack with hsc2hs for working with Haskell and C FFI?

I have a file.hsc in my stack project that would ordinarily need to be pre-processed via hsc2hs file.hsc. Running stack build instead causes the file to be read as a normal haskell file, without preprocessing. Question: Is there a way to use stack…
George
  • 6,927
  • 4
  • 34
  • 67
4
votes
0 answers

cabal cross-compile for ARM issue with hsc2hs

I am trying to cross-compile cabal-install for ARM. It has come down to installing the prerequisite packages one-by-one. I was able to configure, build and install some of the packages by following this page: How do I install dependencies when cross…
rdst15
  • 41
  • 1
4
votes
1 answer

How to make haddock documentation for hsc2hs enum members

I'm using hsc2hs to import a bunch of enum values from C header. My code (simplified) looks like this: -- | newtype wrapper around Windows SDK SE_OBJECT_TYPE enumeration newtype SecurityObjectType = SecurityObjectType BYTE #{enum SecurityObjectType,…
Anton
  • 978
  • 5
  • 11
3
votes
1 answer

How to SPECIALIZE for a hsc2hs type?

I'm trying to use the SPECIALIZE pragma to a type I get through hsc2hs's #type. I tried something like this: {-# SPECIALIZE someFn :: #{type DWORD} -> #{type DWORD} -> Bool #-} someFn :: Eq a => a -> a -> Bool That attempt fails with a parse error…
MasterMastic
  • 20,711
  • 12
  • 68
  • 90
3
votes
1 answer

Interfacing C unions in Haskell via c2hsc and hsc2hs

While using c2hsc and hsc2hs saves me a lot of work, I've run into some trouble when trying to create bindings for C unions. For example, given the C structure typedef struct { int tag; union { char a; double b; …
David
  • 8,275
  • 5
  • 26
  • 36
3
votes
1 answer

Interfacing with the XKB API with hsc2hs

I'm trying to access various bits and bobs in the XKB API. This is my test code so far: {-# LANGUAGE ForeignFunctionInterface #-} module Main where import Foreign import Foreign.C.Types #include #let alignment t = "%lu", (unsigned…
Sarah
  • 6,565
  • 1
  • 33
  • 44
3
votes
1 answer

How can I allocate and re-use a C struct from Haskell?

In particular, I'm trying to learn Haskell's foreign function interface by writing a binding to the Allegro game library. In Allegro's native C, the main event loop looks something like this: // initialize event struct ALLEGRO_EVENT event; // main…
damien
  • 902
  • 1
  • 7
  • 12
2
votes
1 answer

What is % in the Haskell preprocessor and how does it relate to types like Uint8 (if at all)?

I'd like to better understand the following code in general. The instances for MDouble are included in the snippet to demonstrate an example that doesn't use the preprocessor. #let numarray t = "\ foreign import ccall unsafe mxIs%s :: MXArrayPtr ->…
bbarker
  • 11,636
  • 9
  • 38
  • 62
2
votes
0 answers

Using hsc2hs with HPack and Stack

I'd like to use hsc2hs via Stack and HPack. The problem is, since HPack doesn't allow me to list the .hsc file as a source file, only .hs, changes to the .hsc file don't trigger a rebuild in stack build. My package.yaml file is as follows: name:…
Cactus
  • 27,075
  • 9
  • 69
  • 149
1
2