I created some files from a project in Unix, they are a lot and if I want to execute it in another pc or folder I need to copy all files to there. They are all connected in import.
How can I make an executable haskell program?
I have per example:
main.hs - main where all the program executes; using,besides haskell, unix shell.
ex1.hs - basically types of data, some functions.
ex2.lhs - same as ex1.lhs but is literate with LaTeX
pic.jpg - picture to use on the pdflatex
package.sty - package needed to use some functions
How do I proceed and compile all of these?
I tried using ghc but always giving errors:
>ghc -o MAIN main.hs ex1.hs ex2.lhs pic.jpg package.sty
Failed to load interface for 'ex1.hs'
And is in the line which has import ex1.hs
Curious is if I trade import ex1.hs to import ex2.lhs line will give error on ex2
Haskell module names must begin with an upper case letter, so start by renaming
ex1.hsandex2.hstoEx1.hsandEx2.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.hsto correspond to the module names.Now compile with
ghc --make main.hs, and it should find the other modules automatically. It will search for modules with both.hsand.lhsextensions, 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.