Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

ghc - Haskell : loading ALL files in current directory path

The command (in GHCi)

:load abc

Loads the functions in the file abc (which must exist in the current directory path). How would I load all the files in the current directory path? Thanks

----------------------------------------------------------------------------------

[RESPONSE TO POST BELOW]

Hi Rotskoff, thanks I tried your suggestion but I could not get it to work, so I think I must have misunderstood something.

I created 3 files test.hs, test1.hs, and test2.hs as follows :

->

--test.hs
import NecessaryModule

->

--test1.hs
module NecessaryModule where

addNumber1 :: Int -> Int -> Int
addNumber1 a b = a + b

->

--test2.hs
module NecessaryModule where

addNumber2 :: Int -> Int -> Int
addNumber2 a b = a + b

Then when I did :

:load test

I got the error message :

test.hs:1:8:
    Could not find module `NecessaryModule':
      Use -v to see a list of the files searched for.

Thanks

---------------------------------------------------------------------------------

Thanks. This is what I did to get it to work (following Rotskoff's suggestion) :

->

--test.hs
import NecessaryModule1
import NecessaryModule2

->

--NecessaryModule1.hs
addNumber1 :: Int -> Int -> Int
addNumber1 a b = a + b

->

--NecessaryModule2.hs
addNumber2 :: Int -> Int -> Int 
addNumber2 a b = a + b
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Presumably you mean Haskell source files, because you can't use the :load command in GHCi for anything else.

At the top of the source file that you load, include the line:

import NecessaryModule

For each of the source files, make sure to name the modules, e.g.,

module NecessaryModule where

should appear. GHCi will automatically link all the files.

If you're trying to import data, take a look at System.Directory in the documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...