Compile multi .hs files of Haskell - Unix Compile multi .hs files of Haskell - Unix unix unix

Compile multi .hs files of Haskell - Unix


  1. Haskell module names must begin with an upper case letter, so start by renaming ex1.hs and ex2.hs to Ex1.hs and Ex2.hs. They should also start with module Ex1 where, otherwise the module name will default to Main, and GHC will be very confused when the module names don't match the file names.

  2. 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
  3. 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.


Try

ghc --make main.hs

That should make ghc try to do everything it can...