Hello world in Haskell is 1.3 mb

Viewed 647

I'm very disappointed to discover that my Hello World executable in Haskell is 1.3 mb. This is really unacceptable to me. Am I doing something wrong? What excuse is there for having a hello world executable be so large? Is there a reasonable way to cut this down? The same thing in C is 8 kb.

main = print "Hello, worlds"
3 Answers

You don't say which platform or what version of GHC, so I'm making some guesses here.

  1. By default, GHC does not strip debugging symbols. On Linux you can run the strip utility to remove these. On any platform, you can compile with -optl-s to automatically strip debugging symbols during linking.

  2. Depending on exactly which platform you're on and what version of GHC you have, GHC defaults to statically linking all the Haskell libraries you call, and the Haskell runtime system itself (i.e., the garbage collector, thread scheduler, transaction manager, I/O manager...) If supported for your platform, turning on dynamic linking can result in a significant decrease in executable size.

See also

Don't statically link in the libraries (including RTS) into binaries if you want small binaries:

% cat x.c
#include <stdio.h>

int main()
{
    printf("Hello world\n");
}
% gcc x.c && du -h a.out
 12K    a.out
% cat x.hs
main :: IO ()
main = putStrLn "Hello world"
% ghc -dynamic x.hs && du -h x
[1 of 1] Compiling Main             ( x.hs, x.o ) [flags changed]
Linking x ...
 16K    x
Related