RE: How to access defines and enums in a convenient way?
I am doing some wrappers for c functions, and I need to access defines, enums, and structs.
I am doing this by writing access functions in c, so that I can call them from Haskell.
Is there a way to write this c code inline in the Haskell module?
You want to use a tool to make all this easier. There are various tools available: green-card, c2hs, and hsc2hs are the most commonly-used ones these days. Alastair Reid wrote a good comparison of the various tools (can't remember the link off hand though). There are examples of hsc2hs code in the libraries - particularly fptools/libraries/unix has examples of doing defines, enums and structs. Examples of green-card stuff can be found in fptools/libraries/HGL and fptools/libraries/X11. Take a look at Manuel's GtkHS for c2hs examples. Cheers, Simon
You want to use a tool to make all this easier. There are various tools available: green-card, c2hs, and hsc2hs are the most commonly-used ones these days.
Alastair Reid wrote a good comparison of the various tools (can't remember the link off hand though).
It is in: http://www.reid-consulting-uk.ltd.uk/docs/ffi.html I've been trying to update it recently so there's some new answers to FAQs but there's also some empty sections where I plan to write something but haven't yet. -- Alastair Reid
fre 2003-06-06 klockan 12.06 skrev Alastair Reid:
You want to use a tool to make all this easier. There are various tools available: green-card, c2hs, and hsc2hs are the most commonly-used ones these days.
Alastair Reid wrote a good comparison of the various tools (can't remember the link off hand though).
It is in:
http://www.reid-consulting-uk.ltd.uk/docs/ffi.html
I've been trying to update it recently so there's some new answers to FAQs but there's also some empty sections where I plan to write something but haven't yet.
hsc2hs solved my problem! It would be even greater if ghc --make could accept .hsc as source and not generate a .hs file at all, like it does with .lhs. hsc2hs is distributed with ghc after all. I actually could persuade ghc to do almost what I want by writing this little wrapper (hscwrapper): #!/bin/sh hsc2hs $2 -o $3 then simply write .chs code directly in the .hs file and calling ghc -pgmF hscwrapper -F --make However, -pgmF is a static option (why is that?) so I can't put it in the .hs file. This means hsc2hs has to be run for all files and the compilation goes a bit slower. Regards, Martin -- Martin Norbäck d95mback@dtek.chalmers.se Kapplandsgatan 40 +46 (0)708 26 33 60 S-414 78 GÖTEBORG http://www.dtek.chalmers.se/~d95mback/ SWEDEN OpenPGP ID: 3FA8580B
Martin Norbäck <d95mback@dtek.chalmers.se> writes:
hsc2hs solved my problem! It would be even greater if ghc --make could accept .hsc as source and not generate a .hs file at all, like it does with .lhs.
Just a quick reminder that although 'ghc --make' does not know about preprocessors, 'hmake' does, and should be able to handle .hsc files automatically exactly as you wish. Regards, Malcolm
fre 2003-06-06 klockan 14.55 skrev Malcolm Wallace:
Martin Norbäck <d95mback@dtek.chalmers.se> writes:
hsc2hs solved my problem! It would be even greater if ghc --make could accept .hsc as source and not generate a .hs file at all, like it does with .lhs.
Just a quick reminder that although 'ghc --make' does not know about preprocessors, 'hmake' does, and should be able to handle .hsc files automatically exactly as you wish.
Weel as I said, I got ghc --make to work by giving it a pair of extra arguments, which I suppose I would have to do with hmake as well. My main arguments for using ghc --make instead of hmake is that I can avoid the startup time for ghc (hmake calls it once per source file), and that it does more fine-grained dependency, so that if the interface of a module is unchanged, modules that depend on it need not be recompiled. Maybe the last one is fixed now. And the solution I gave (-pgmF) also works for ghci (it probably invokes the same functions as --make does). But since hsc2hs is (somewhat) integrated into ghc, I see no reason (apart from the fact that someone has to implement it of course) why --make shouldn't be able to handle .hsc files automatically without extra arguments. Regards, Martin -- Martin Norbäck d95mback@dtek.chalmers.se Kapplandsgatan 40 +46 (0)708 26 33 60 S-414 78 GÖTEBORG http://www.dtek.chalmers.se/~d95mback/ SWEDEN OpenPGP ID: 3FA8580B
participants (4)
-
Alastair Reid -
Malcolm Wallace -
Martin Norbäck -
Simon Marlow