Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
Manuel M T Chakravarty - C->Haskell
[go: Go Back, main page]

C->Haskell, An Interface Generator for Haskell

hackageDB
  :: [Package]
package
FreshPorts entry
Debian packages

C->Haskell is an interface generator that simplifies the development of Haskell bindings to C libraries. The tool processes existing C header files that determine data layout and function signatures on the C side in conjunction with Haskell modules that specify Haskell-side type signatures and marshaling details. Hooks embedded in the Haskell code signal access to C structures and functions -- they are expanded by the interfacing tool in dependence on information from the corresponding C header file. Another noteworthy property is the lightweight nature of the approach. The idea for the tool was developed during the implementation of Gtk+HS, a Haskell binding for the GUI toolkit GTK+. The latter is no longer under active development, but its successor, Gtk2Hs, also uses C->Haskell.

The generator is implemented using the Compiler Toolkit and in particular the self-optimising lexer and parser combinators of the toolkit. The use of the toolkit simplified the implementation of C->Haskell considerably.

The latest news:

  • [24 November 2007] *new* Duncan Coutts just released version 0.15.1 "Rainy Days". This release builds with GHC 6.4 through to 6.8 and also properly supports OpenBSD and Windows. Moreover, the documentation has been updated.
  • [31 August 2007] Duncan Coutts just released version 0.15.0 "Rainy Days". This release includes Duncan's new parser with excellent gcc compatibility and an improved build system.
  • [2 January 2006] Updated the the C->Haskell darcs repository with modifications by Ganesh Sittampalam to fix a problem when pulling on windows/cygwin.
  • [14 May 2006] The C->Haskell darcs repository moved to darcs.haskell.org and Duncan Coutts is now a second maintainer of the tool. (He's the one who heroically rewrote C->Haskell's parser.)
  • [12 December 2005] Source release 0.14.5 brings in addition to bug fixes support for typedef'ed pointers to structs/unions (thanks to Jelmer Vernooij) and enables to suppress code generation for pointer hooks with a nocode directive.

Currently, the C->Haskell compiler is available for the Glasgow Haskell Compiler only. However, the only extension needed over Haskell 98 and the H98 FFI Addendum are existential data types. (The latter are only needed for the C->Haskell compiler itself, but not for the accompanying marshaling libraries.) Partial support for nhc98 is in place, but so far there have always been some bugs in nhc98 that prevented to complete the port.

Current Status

Most of the major features that I have planned for C->Haskell are implemented and are working. The system has an easy to use build system (Cabal-style ./Setup.hs configure; ./Setup.hs build; ./Setup.hs install) and basic documentation is in place. The system is getting close to its 1.0 release.

Releases

The following lists source and binary packages of C->Haskell. Note that the binary packages are compiled for use with GHC and that the included marshalling libraries will only work with exactly the version of GHC that they have been compiled for.

c2hs-0.15.1 [ tar.gz | Hackage DB entry ]
Builds with GHC 6.4-6.8, updates docs, and builds on FreeBSD and Windows.
c2hs-0.15.0 [ tar.gz | Fedora RPMs | i386.deb | FreeBSD port | ArchLinux Pkg ]
New parser with excellent gcc compatibility and improved build system.
c2hs-0.14.5 [ tar.gz | Fedora RPMs | i386.deb | FreeBSD port | ArchLinux Pkg ]
Improved support for pointer hooks.
c2hs-0.13.6 [ tar.gz | Fedora RPMs | i386.deb | FreeBSD port | ArchLinux Pkg ]
This release includes support for GHC 6.4, which was kindly provided by André Pang.

Mailing List

To subscribe to the C->Haskell mailing list, visit the subscription page. The address of the list is c2hs@haskell.org and there is also an online archive.

Darcs Repository

For those living on the bleeding edge of development, get the latest C->Haskell code per darcs with

darcs get http://darcs.haskell.org/c2hs/

Inside your copy of the repository, execute autoconf; chmod +x Setup.hs. Afterwards compilation/installation is as from a tar ball (i.e., Cabal style ./Setup.hs configure; ./Setup.hs build; ./Setup.hs install). Details are in the file INSTALL.

NB for Mac users: One of the patches originating from the cvs to darcs conversion of the repository seems to cause problems on Macs (due to the lack of case distinction in file names). The patch can be circumvented by getting a partial repository as follows:

darcs get --partial http://darcs.haskell.org/c2hs/

Online viewing: If you like to query the C->Haskell repository without making a local copy, try the darcs repository viewer.

RSS feed: Repository change messages are also available via rss.

Bug reports and feature requests

We'll use Trac to track bugs and feature requests in the future. (Not much there yet.)

Documentation

If you plan to install C->Haskell, you probably like to read the C->Haskell Tutorial. There is also a research paper about the tool. To get an idea of how to use the interface generator -- after the build -- go to the directory c2hs/tests/, which contains a number of small examples of binding files with matching C header files. Most interesting is Structs.chs as well as Pointer.chs as well as the corresponding C source and header files. The binding file contains instructions on how to generate an executable from it.

Future Development

The current version is slated to become version 1.0 after some small extensions and some more testing.

If you have any comments, suggestions, or a bug report, please send them to c2hs@haskel.org. Code contributions are of course especially welcome. Just darcs send them.

License

The code is released under the GNU General Public Licence (GPL). This means that you can basically do with it what you want as long as you contribute improvements of the tool itself back to the community. Any interfaces that you generate with the tool are, however, free from any license restrictions from my side. The situation is exactly the same as with the GNU C Compiler (gcc).

• Copyright [2005..2006] Manuel M T Chakravarty • Last modified: Tue Jan 2 13:15:19 EST 2007