可能重复:
用GHC编译成小二进制的小Haskell程序
最近我注意到Haskell可执行文件有多大.下面的所有内容都是-O2在Linux 上用GHC 7.4.1编译的.
Hello World(main = putStrLn "Hello World!")超过800 KiB.strip在它上面运行会将文件大小减少到500 KiB; 甚至添加-dynamic到编译中也没有多大帮助,让我在400 KiB附近删除了一个可剥离的可执行文件.
编译涉及Parsec的非常原始的示例产生1.7 MiB文件.
-- File: test.hs
import qualified Text.ParserCombinators.Parsec as P
import Data.Either (either)
-- Parses a string of type "x y" to the tuple (x,y).
testParser :: P.Parser (Char, Char)
testParser = do
a <- P.anyChar
P.char ' '
b <- P.anyChar
return (a, b)
-- Parse, print result.
str = "1 2"
main = print $ …Run Code Online (Sandbox Code Playgroud)