I want to call a Haskell function that works with text and returns text (in fact, the processing is complex and the Haskell code is split into several modules, but this is probably not the case).
I tried the approach described here: The relationship between Java and Haskell and modified it to work with strings.
But I get an error message:
error: initializing argument 1 of ‘void* myFunction_hs(HsPtr)’ [-fpermissive]
extern HsPtr myFunction_hs(HsPtr a1);
^
Relevant code and compilation are here: in Haskell:
foreign export ccall myFunction_hs :: CString -> IO CString
in Java:
import com.googlecode.javacpp.*;
import com.googlecode.javacpp.annotation.*;
@Platform(include={"<HsFFI.h>","myModule_stub.h"})
public class MyModule {
static { Loader.load(); }
public static native void hs_init(int[] argc, @Cast("char***") @ByPtrPtr PointerPointer argv);
public static native String myFunction_hs(String text);
public static void main(String[] args) {
hs_init(null, null);
String s = myFunction_hs("This is some String.");
System.out.println("Result: " + s);
}
}
And compilation:
$ ghc -fPIC -c -O myModule.hs
$ javac -cp javacpp.jar MyModule.java
$ java -jar javacpp.jar -Dcompiler.path=ghc -Dcompiler.output.prefix="-optc-O3 -Wall MyModule.o -dynamic -fPIC -shared -lstdc++ -lHSrts-ghc7.6.3 -o " -Dcompiler.linkpath.prefix2="-optl -Wl,-rpath," MyModule
Do you have any ideas what went wrong?
source
share