I'm experimenting with the haskell FFI, and have run into a odd little
problem.  For some reason, ghc won't let me import functions with no
arguments...

Here's my C file (hw.c)
#include <stdio.h>

void hiworld(void)
{
    printf("Hello, haskell world!\n");
}

Compiled to a shared library with
$ gcc --shared -c -o hw.so hw.c

And my first try (for.hs)

foreign import ccall "hiworld.so" "hiworld" hiworld :: () -> IO () 

main = hiworld ()

and I get:
$ ghc for.hs hw.so -fglasgow-exts
for.hs:5:
    Unacceptable argument type in foreign declaration: ()
    When checking declaration:
        foreign import _ccall "hiworld.so" "hiworld" hiworld :: () -> IO
()

Alright then, so I tried something else:

foreign import ccall "hiworld.so" "hiworld" hiworld :: IO () -> IO () 

main = hiworld ()

gets

for.hs:5:
    Unacceptable argument type in foreign declaration: IO ()
    When checking declaration:
        foreign import _ccall "hiworld.so" "hiworld" hiworld :: IO ()
                                                                -> IO ()

for.hs:7:
    Couldn't match `IO ()' against `()'
        Expected type: IO ()
        Inferred type: ()
    In the first argument of `hiworld', namely `()'
    In the right-hand side of a pattern binding: hiworld ()


Could someone help me with the right syntax here?

           ------------------ Peter Amstutz --------------------
           -------------- [EMAIL PROTECTED] -------------
           ------- http://www-unix.oit.umass.edu/~tetron -------
           -----------------------------------------------------


Reply via email to