50

Demo of using Haskell in a C project

 5 years ago
source link: https://www.tuicool.com/articles/hit/M7Zf6be
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Is it a C project or a Haskell project?

The main program is C, but selected functions can be Haskell. For those parts where automatic memory management, great numeric libraries, containers, Unicode support, or parsing is useful, do it with Haskell. For other parts where an imperative algorithm is the easiest way to do something, or where memory should be managed more carefully, do it in C.

This approach doesn't even use Cabal, just a portable makefile and the functionality of GHC itself. The Haskell code has access to a useful set of libraries which ships with every GHC installation. This includes a Haskell interface to POSIX.1-2008.

By linking dynamically to the GHC runtime, the executable can stay small at only a few kilobytes.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK