Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell -- how to use multiple modules in the same file?

Tags:

module

haskell

Sorry this is a dumb question, but I cannot figure out how to put multiple modules in the same file. Suppose the file is named A.hs. If I put module B first, i.e.

module B where ...
module A where ...

it complains that it expected A when I run "ghci A" (It's not top-level, so I don't want to call "ghci A.hs"). The other way around, and it complains "parse error on input module").

There's a related bug here, http://hackage.haskell.org/trac/ghc/ticket/2428 . Is there actually no way to get this, even if the other module is only used locally?

like image 961
gatoatigrado Avatar asked Aug 03 '11 06:08

gatoatigrado


2 Answers

You cannot have multiple modules in the same file. The bug you linked to is just about the error message given by GHC not being clear about this.

However, if you're using Cabal, you can still control the visibility of modules by putting the modules you want visible to users in the Exposed-Modules section, and putting any internal modules in Other-Modules.

like image 65
hammar Avatar answered Oct 23 '22 05:10

hammar


I found the following bug report.

Which refers to this mailing list item, which states:

No, that's not possible because haskell will use the module name A.B.C to look the module up in path A/B/C.[l]hs.
So using modules
module A where
..
module B where
the compiler could only find one of them. (naming the file A.hs or B.hs)
You have to use one file for each module

So, I guess the answer is no.

like image 8
Legolas Avatar answered Oct 23 '22 04:10

Legolas