foreign export stdcall on user-defined type and function
Simon Marlow
simonmar at microsoft.com
Mon Nov 8 09:48:57 EST 2004
On 08 November 2004 02:49, David Lo wrote:
> I'm new in haskell. I'm assigned to see that a piece of Haskell code
> need to be callable from C#. I find that I can convert Haskell to DLL
> using ghc --mk-dll.
>
> I find it is fine for simple function but for the following errors are
> reported.
>
> foreign export stdcall doComp :: Pattern -> CString -> IO ()
> doComp :: Pattern -> CString -> IO ()
>
> foreign export stdcall evalDisplay :: RealFrac a => CString ->
> (Int->VMC (Maybe a)) -> IO ()
> evalDisplay :: RealFrac a => CString -> (Int->VMC (Maybe a)) -> IO ()
It would help if you posted the entire code, rather than just a snippet.
We can't tell for sure where the errors are without seeing the
definitions for some of the types you've used, for example.
> The errors are as follows:
>
> Compiling Main ( CPL.hs, interpreted )
>
> CPL.hs:29:
> Unacceptable argument type in foreign declaration:
> forall a b c. (Ind a c, Compare c b) => Pat a b
> When checking declaration:
> foreign export stdcall "doComp" doComp :: Pattern-> CString
> -> IO ()
The error indicates that you have declared a foreign exported function
with a type that does not have a direct translation into a C type. The
legal types for foreign exported functions are described in the FFI
specification, which can be found online here:
http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi.pdf
> CPL.hs:107:
> Unacceptable argument type in foreign declaration: {RealFrac a}
> When checking declaration:
> foreign export stdcall "evalDisplay" evalDisplay :: forall a.
> (RealFrac a) => CString-> (Int -> VMC (Maybe a)) -> IO ()
>
> CPL.hs:107:
> Unacceptable argument type in foreign declaration:
> Int -> VMC (Maybe a)
> When checking declaration:
> foreign export stdcall "evalDisplay" evalDisplay :: forall a.
> (RealFrac a) =>CString-> (Int -> VMC (Maybe a)) -> IO ()
>
> I would like to inquire on how to use foreign function stdcall on self
> defined data structure and function. Can I just simply cast them to
> string ?
Perhaps you could give more details about what you want to do. What
Haskell functions do you want to export to C#, and what types do they
have (both in Haskell and C#)? If you want to export Haskell data
structures to C#, then you have to "marshal" the data into C#, by
converting the Haskell representation into a representation that C# can
understand. Using strings is one possibility, but it's unlikely to be
the best.
Cheers,
Simon
More information about the Glasgow-haskell-users
mailing list