
- -------- import Foreign.C (CInt) return3 :: IO CInt return3 = return 3 foreign export ccall return3 :: IO CInt main = putStrLn "okay" - --------
Well thinking about what this says it says "make the function 'return3' available to the C world as a C function". This is easy to arrange in GHC, just compile in an extra C-World function that converts the arguments and calls the Haskell world. However Yhc (very deliberately) doesn't generate C code, it generates byte code. The bytecode is then loaded at runtime, so if you want foreign exports then there are a couple of options, none of which are very nice: 1) Have a -wrap option to yhc which generates a C file with the wrapper functions in. This works but then there needs to be a special case for Yhc in peoples makefiles that knows to compile the generated C file with the rest of the C code. 2) Generate machine code at runtime. There is no even vaguely portable method for doing this, so it would have to be implemented on a case by case basis. I would also argue that generating machine code is rather against the spirit of Yhc's "clean and simple" design. Of the two I think 1) is the better option, but any solution is going to be nasty when implementing an FFI that was essentially designed for compilers that generate C code. So suggestions are welcome, but ultimately I can't see a "nice" solution :-) Thanks Tom