Search code examples
haskellffi

How do you call a void C function in Haskell


I am attempting to call the main function of a C file in Haskell using the foreign function interface.

The main function is declared:

int main(void);

I am unable to figure out what to tell the Haskell function to do with the void type. I am unable to modify the C source code.

Any help is appreciated.


Solution

  • A function that "takes" void like that in C takes no arguments (this looks like more of a C question than a Haskell question). The type to import it with would just be IO Int.

    (Note that it may not be a good idea to call an actual main function from Haskell via the FFI. But that's up to you.)