<div dir="ltr">Please, I just can not figure this out:<div><br></div><div>I have a method in my C dll:</div><div><div><font face="courier new, monospace">int somemethod(char *param, int length, double array[], int UB1, int UB2, bool isValid);</font></div>
</div><div><br></div><div>I would like to use this method in Haskell, so I have defined it like:</div><div><br></div><div><br></div><div><font face="courier new, monospace">{-# OPTIONS_GHC -fglasgow-exts #-}<br></font></div>
<div><div><font face="courier new, monospace">import Foreign</font></div><div><font face="courier new, monospace">import Foreign.C</font></div></div><div><br></div><div><div><font face="courier new, monospace">foreign import stdcall unsafe "somemethod" c_somemethod :: Ptr CString </font></div>
<div><font face="courier new, monospace"> -> Int </font></div><div><font face="courier new, monospace"> -> Ptr (Double)</font></div>
<div><font face="courier new, monospace"> -> Int </font></div><div><font face="courier new, monospace"> -> Int</font></div>
<div><font face="courier new, monospace"> -> Bool</font></div><div><font face="courier new, monospace"> -> IO Int</font></div>
</div><div><div><font face="courier new, monospace">main = do</font></div><div><font face="courier new, monospace"> let param = ["input"]</font></div><div><font face="courier new, monospace"> let paramLength = length param</font></div>
<div><font face="courier new, monospace"> realTable = [ 1.0, 2.0, 3.0 ] :: [Double]</font></div><div><font face="courier new, monospace"> ub1 = 0</font></div><div><font face="courier new, monospace"> ub2 = 2</font></div>
<div><font face="courier new, monospace"> isValid = False</font></div><div><font face="courier new, monospace"> realTablePtr <- newArray realTable</font></div><div><font face="courier new, monospace"> x <- c_somemethod param paramLength realTablePtr ub1 ub2 isValid</font></div>
<div><font face="courier new, monospace"> free realTablePtr</font></div><div><font face="courier new, monospace"> putStrLn $ "</font><span style="font-family:'courier new',monospace">c_somemethod</span><font face="courier new, monospace"> output: " ++ show x</font></div>
<div><font face="courier new, monospace"> putStrLn "Done"</font></div></div><div><br></div><div><br></div><div>When I try to compile this I get error regarding the param string. I have no idea how to define it. Additionally to this, is the freeing of <span style="font-family:'courier new',monospace">realTablePtr </span><font face="arial, helvetica, sans-serif">correct?</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">compile error:</font></div><div><div><font face="courier new, monospace"> Couldn't match expected type `Ptr CString' with actual type `[t0]'</font></div>
<div><font face="courier new, monospace"> In the first argument of `c_somemethod', namely `param'</font></div></div><div><font face="courier new, monospace"><br></font></div><div>Please, how can I ix this?<font face="courier new, monospace"><br>
</font></div><div><br></div><div>cheers,</div><div>m.</div></div>