[Haskell-cafe] foreign export space-leaks?

James Ge jge666 at gmail.com
Fri Feb 20 21:53:23 EST 2009

first I wrote a silly haskell program:

--- a program to walk through very long list ----

data Silly = A !Int | B !Int deriving (Show)

main =
  go [a + b | a <- [0..10000], b <- [0..10000]]

  go [] = do
      putStrLn $ "completed."

  go (x:xs) = do
      case even x of
          True -> putStrLn $ show (A x)
          False -> putStrLn $ show (B x)
      go xs
---------- end of the program -----------

upper program ran well, and consumed fixed memory (2.8M watched by
but when I exported the main to C and host the whole haskell program
in C, memory consumption increased CONSTANTLY.

what I did are:
1) explicit name the module to `Silly' and rename `main' to
2) write a c wrapper following guildlines here(http://www.haskell.org/

--- c wrapper code begins ----
#include <stdio.h>
#include "HsFFI.h"

#include "Silly_stub.h"

extern void __stginit_Silly ( void );

int main()
 hs_init(0, 0);


 return 0;

---- wrapper code ends -----

then I compiled them together:
---- Makefile section begins -----
      ghc -O2 --make Silly.hs
      ghc -O2 --make Silly_wrapper.c
      ghc -O2 -o Silly.out *.o
-----Makefile sect ends -----------

this program consumed memory constantly until the process being
terminated by OS because of `out of memory'. I guess this must have
something to do with GC (although i tried import hs_perform_gc
declared in HsFFI.h and called the function, but i didn't see any
change), do you have ideas?

Thanks in advance,

More information about the Haskell-Cafe mailing list