Multiple source files in Haskell

I am writing my first big project in Haskell, and I would like to split it into several files. So far I have written two modules: Parse and Eval . I would like to have a Main module that includes only these two modules and defines the Main function. I have Main.hs , Parse.hs and Eval.hs and import them into Main , but this happens:

 Prelude> :load "~/code/haskell/lisp/Main.hs" [1 of 3] Compiling Eval ( Eval.hs, interpreted ) [2 of 3] Compiling Parse ( Parse.hs, interpreted ) [3 of 3] Compiling Main ( ~/code/haskell/lisp/Main.hs, interpreted ) Ok, modules loaded: Main, Parse, Eval. *Main> parse parseExpr "" "#b101" <interactive>:1:0: Not in scope: `parse' 

The Parse function comes from the Parsec library, which is imported into Parse.hs . What's wrong?

+4
source share
2 answers

From the Haskell report :

A module implementation can export an object that it declares, or that it imports from some other module. If the export list is omitted, all values, types, and classes defined in the module are exported, but not those imported.

You need to specify an explicit export list that includes parse in Parse.hs , or import parse again in Main.hs

+4
source

You can also do this:

 module Parse (parse) where import qualified Text.ParserCombinators.Parsec as P parse = P.parse 

But actually it is useless. Of course, you will want to create something more than a domain on top of Parsec before exporting it from one of your modules.

+1
source

All Articles