ghc - Using #if-#else-#endif in Haskell -


i have 2 versions of same program little changes between two. instead of having separate files, use #if defined (par) - #else - #endif , compile or without -cpp -dpar switch between 2 versions. way have work on single hs file. however, since aim write parallel/optimised version of original program, wonder if using #if-#else#-endif has performance implication? explanation of how works under hood. thanks

#if defined(par) import control.parallel import control.parallel.strategies import control.deepseq #endif  #if defined(par) test = sum ( map expensivefunc mylist `using` strat )     strat = parlistchunk 100 rseq #else  test = sum ( map expensivefunc mylist ) #endif 

note:

instead of -cpp flag, use language options in source file:

e.g. {-# language cpp #-}

but still need provide (or not) -dxxx when compiling in order choose part of program compiler should ignore ( xxx defined variable in hs file).

c preprocessor directives in effect during compilation. compiler cuts out lines within #ifdef block , compiles program usual, there no runtime performance penalty.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -