Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem Specifying Source Directory to GHC

Tags:

haskell

ghc

This is an embarrassingly simple problem, but its solution yet eludes me. As the title indicates, I simply want to specify to GHC the location of all my source files. This should be simple; the GHC user guide:

-idirs

This flag appends a colon-separated list of dirs to the search path.

So, I tried the following invocations:

ghc -isrc/ -v -outputdir build/ --make -Wall Main.hs
ghc -isrc/: -v -outputdir build/ --make -Wall Main.hs
ghc -i:src/: -v -outputdir build/ --make -Wall Main.hs
ghc -i"src/" -v -outputdir build/ --make -Wall Main.hs
ghc -i"src/": -v -outputdir build/ --make -Wall Main.hs
ghc -i:"src/": -v -outputdir build/ --make -Wall Main.hs

On every invocation GHC gave the error: "<no location info>: can't find file: Main.hs"

As you probably could have guessed, Main.hs is located in a subdirectory from the working directory called "src". Just in case it matters, I'm on Windows XP, and I'm using GHC 6.12.2. I'm assuming there is some small problem that I'm just missing.

like image 840
Bface Avatar asked Apr 22 '11 21:04

Bface


People also ask

How do I change directories in Haskell?

:cd -- change to another directory. :type [expr] -- give the type of an expression (or -- just :t) :set +t tell Haskell to print type information after evaluation.

How do I load files into ghci?

From the command line, enter "ghci" (or "ghci -W") followed by an optional filename to load. Note: We recommend using "ghci -W", which tells GHC to output useful warning messages in more situations. These warnings help to avoid common programming errors.

How do I load a Haskell file into ghci?

Open a command window and navigate to the directory where you want to keep your Haskell source files. Run Haskell by typing ghci or ghci MyFile. hs. (The "i" in "GHCi" stands for "interactive", as opposed to compiling and producing an executable file.)

How do I open ghci in terminal?

If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt. Alternatively, if you are on Windows, you may choose WinGHCi in the Start menu.


1 Answers

-i specifies where GHC will search for other source files, other than the ones you specify on the command line. So your Main.hs there will also need a src/ prefix. E.g.

$ ghc -isrc src/Main.hs --make 
[1 of 1] Compiling Main             ( src/Main.hs, src/Main.o )
Linking src/Main ...

Alternatively, you could use cabal, and have cabal init generate all the build metadata for you.

like image 179
Don Stewart Avatar answered Oct 05 '22 20:10

Don Stewart