Compile multi .hs files of Haskell - Unix
Haskell module names must begin with an upper case letter, so start by renaming
ex1.hs
andex2.hs
toEx1.hs
andEx2.hs
. They should also start withmodule Ex1 where
, otherwise the module name will default toMain
, and GHC will be very confused when the module names don't match the file names.Import statements should refer to the module name, not the file name, so change them in
main.hs
to correspond to the module names.import Ex1import Ex2
Now compile with
ghc --make main.hs
, and it should find the other modules automatically. It will search for modules with both.hs
and.lhs
extensions, and correctly treat the latter like literate Haskell files.
For larger projects, you should look into using Cabal, the build system used by most Haskell libraries and programs. It will help with managing dependencies and compiler options, sort of like a Makefile.