title: Calling Haskell function returning String from Java
body: <p>I want to call a Haskell function that is operating on text and returns text (actually the processing is complicated and the Haskell code is split into few modules, but this probably isn't the case).</p>
  
  <p>I tried the approach described here: <a href="https://stackoverflow.com/questions/10370177/communication-between-java-and-haskell">Communication between Java and Haskell</a> and modified it to work with Strings.</p>
  
  <p>But I'm getting the error:</p>
  
  <pre><code> error:   initializing argument 1 of ‘void* myFunction_hs(HsPtr)’ [-fpermissive]
   extern HsPtr myFunction_hs(HsPtr a1);
                ^
  </code></pre>
  
  <p>The relevant code and compilation is here:
  in Haskell:</p>
  
  <pre><code>foreign export ccall myFunction_hs :: CString -&gt; IO CString
  </code></pre>
  
  <p>in Java:</p>
  
  <pre><code>import com.googlecode.javacpp.*;
  import com.googlecode.javacpp.annotation.*;
  
  @Platform(include={"&lt;HsFFI.h&gt;","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);
      }
  }
  </code></pre>
  
  <p>And the compilation:</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>Do you have any idea what goes wrong?</p>