
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]]
where
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
top).
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
`call_me_back'
2) write a c wrapper following guildlines here(http://www.haskell.org/
ghc/docs/latest/html/users_guide/ffi-ghc.html#hs-exit):
--- c wrapper code begins ----
#include