3

I am using the Haskell app for OS X, and have created a Haskell project, and when I create another file in the project, Haskell tells me that the file name and path do not match the module name! I am new to Haskell, what does this mean?

It is telling me also that it is expecting the name of the file as the module name.

Thanks!

5
  • So what is the module name of your module (thats the word that follows module in its source code)? and what is the filename? Please make sure that you copy&paste these answers, because upper/lowercase-issues are important here. Commented Sep 13, 2015 at 15:55
  • The name of the .hs file is just NewModule.hs at the moment, as I am just testing things. The file is completely empty. Commented Sep 13, 2015 at 16:01
  • the file should contain at least the line module NewModule; Commented Sep 13, 2015 at 16:02
  • 2
    "The Haskell app for OS X" doesn't mean anything. Are you talking about GHC, GHCi, cabal, stack, or something weird? Commented Sep 13, 2015 at 16:10
  • Nevermind, I got it working with the help of Michael. There is an app on the Mac appstore just called 'Haskell' which is what I use. It's just a Haskell IDE. Sorry for being vague. Commented Sep 13, 2015 at 16:20

1 Answer 1

7

The error message tells you that the module name and the file name should be the same.

E.g.: If the file name is NewModule.hs, the module name should be NewModule. E.g.

-- NewModule.hs:

module NewModule where

-- you may define functions here...

So, you just have to use the module directive.

Sign up to request clarification or add additional context in comments.

3 Comments

That didn't work, but I used 'module NewModule where' and it worked. What does the 'where' part mean?
@manwholikesspritekit where introduces a block of declarations. For example when you define a function you can say: f x y = ... where a = ... so the where a = ... defines some names that can be used in the body of the function. The whole module can be seen as such a block.
"In particular, there is no connection between module names and file names, and more than one module could conceivably reside in a single file (one module may even span several files). Of course, a particular implementation will most likely adopt conventions that make the connection between modules and files more stringent." This is from document of GHC, in this case if file name not same as module name, i dont know how GHC will look for file to import when I import module X from file Y.hs. haskell.org/tutorial/modules.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.