My Code:
getGPS :: String -> IO (Double, Double)
getGPS ip = do
html <- getHTML ip
let ztags =Prelude.zip [0..] . filterStr . getTagText . getTags $ html
let nlat = Prelude.head $ Prelude.map fst . Prelude.filter (\(_, str) -> strEq str ("Latitude:" :: String)) $ ztags
let nlng = Prelude.head $ Prelude.map fst . Prelude.filter (\(_, str) -> strEq str ("Longitude:" :: String)) $ ztags
let lat = read (Prelude.head $ Prelude.map snd . Prelude.filter (\(n, _) -> n == nlat + 1) $ ztags) :: Double
let lng = read (Prelude.head $ Prelude.map snd . Prelude.filter (\(n, _) -> n == nlng + 1) $ ztags) :: Double
return (lat, lng)
is working fine. Now i wanna export this function via FFI
to access it from an C application. I did foreign export ccall getGPS :: CString -> IO (CDouble, CDouble)
but this is not working:
GPS.hs:45:1:
Illegal foreign declaration: requires unregisterised, llvm (-fllvm) or native code generation (-fasm)
When checking declaration:
foreign export ccall "getGPS" getGPS
:: CString -> IO (CDouble, CDouble)
GPS.hs:45:1:
Unacceptable result type in foreign declaration:
‘(CDouble, CDouble)’ cannot be marshalled in a foreign call
When checking declaration:
foreign export ccall "getGPS" getGPS
:: CString -> IO (CDouble, CDouble)
GPS.hs:45:1:
Couldn't match type ‘Double’ with ‘CDouble’
Expected type: CString -> IO (CDouble, CDouble)
Actual type: String -> IO (Double, Double)
In the expression: getGPS
When checking declaration:
foreign export ccall "getGPS" getGPS
:: CString -> IO (CDouble, CDouble)
Failed, modules loaded: none.
How to export this function correctly?