Are there any good ways to make small haskell executables? With ghc6 a simple hello world program seems to come to about 370kB (523kB before strip). Hello world in C is about 4kB (9kB before strip).
With the development branch of GHC (anyone know exactly which version this was added in?):
$ ghc -o hello hello.hs
$ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello
$ du hello hello-small
700 hello
476 hello-small
Add the -dynamic flag for a dynamically linked RTS:
$ ghc -dynamic -o hello hello.hs
$ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello
$ du hello hello-small
24 hello
16 hello-small
See also: http://hackage.haskell.org/trac/ghc/wiki/SharedLibraries/PlatformSupport
For comparison with C:
$ gcc hello.c -o hello
$ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello
$ du hello hello-small
12 hello
8 hello-small
GHC is statically linking everything (except libraries used by runtime itself, which are linked dynamically).
In the old ages, GHC linked the whole (haskell) library in as soon as you've used something from it. Sometime ago, GHC started to link "per obj file", which drastically reduced the binary size. Judging from the size, you must've been using the newer GHC already.
On the plus side, you already have a lot of stuff in those 500K, like multithreaded core, garbage collector etc.
Add at least garbage collector to your C code, then compare them again :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With