Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to compile "only a file" in a cabal project?

Tags:

haskell

ghc

cabal

In JVM based programs, you can compile a file to a .class file and be able to run the binary again, without compiling necessarily all the files.

Is it possible to do it in haskell? Is it imperative to compile and link all the files in the project? If yes, why?

What if there is no binary, you are only installing a library?

like image 641
Carlos López-Camey Avatar asked Nov 29 '25 16:11

Carlos López-Camey


1 Answers

For GHC, you can change and recompile a single module without having to recompile modules depending on that, provided the exposed interface doesn't change. GHC's --make mode (default as of ghc-7.*) checks whether recompilation is necessary and recompiles only those modules where it can't determine that it's not necessary.

If you have a cabal package and you cabal build after changing one module, you can see from the compiler output that it doesn't recompile all modules in the package in general, only the changed module and [maybe] the ones depending on it.

If you build an executable, that of course has to be relinked, but many of the old object files can be reused.

If you build a library, the library archive of course has to be rebuilt, but many of the old object files can be reused.

like image 99
Daniel Fischer Avatar answered Dec 02 '25 06:12

Daniel Fischer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!