haskell - Compiling very large constants with GHC -


today asked ghc compile 8mb haskell source file. ghc thought about 6 minutes, swallowing 2gb of ram, , gave out-of-memory error.

[as aside, i'm glad ghc had sense abort rather floor whole pc.]

basically i've got program reads text file, fancy parsing, builds data structure , uses show dump file. rather include whole parser , source data in final application, i'd include generated data compile-time constant. adding stuff output show, can make valid haskell module. ghc apparently doesn't enjoy compiling multi-mb source files.

(the weirdest part is, if read data back, doesn't take time or memory. strange, considering both string i/o , read supposedly inefficient...)

i vaguely recall other people have had trouble getting ghc compile huge files in past. fwiw, tried using -o0, speeded crash did not prevent it. is best way include large compile-time constants in haskell program?

(in case, constant nested data.map interesting labels.)

initially thought ghc might unhappy @ reading module consisting of 1 line that's 8 million characters long. (!!) layout rule or such. or perhaps deeply-nested expressions upset it. tried making each subexpression top-level identifier, , no help. (adding explicit type signatures each 1 did appear make compiler happier, however.) there else might try make compiler's job simpler?

in end, able make data-structure i'm trying store smaller. (like, 300kb.) made ghc far happier. (and final application faster.) future reference, i'd interested know best way approach is.

your best bet compile string representation of value executable. in clean manner, please refer my answer in previous question.

to use it, store expression in myexpression.exp , read [litfile|myexpression.exp|] quasiquotes extension enabled, , expression "stored string literal" in executable.


i tried doing similar storing actual constants, fails same reason embedding value in .hs file would. attempt was:

verbatim.hs:

module verbatim  import language.haskell.th import language.haskell.th.quote import language.haskell.meta.parse  readexp :: string -> q exp readexp = either fail return . parseexp  verbatim :: quasiquoter verbatim = quasiquoter { quoteexp = readexp }  verbatimfile :: quasiquoter verbatimfile = quotefile verbatim 

test program:

{-# language quasiquotes #-} module main (main)  import verbatim  main :: io () main = print [verbatimfile|test.exp|] 

this program works small test.exp files, fails @ 2mib on computer.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -