module ‘main:Main’ is defined in multiple files

Viewed 101

I have tried to load a file by typing ghc Interact Interact.hs

This produces the following error:

  <no location info>: error:
     module ‘main:Main’ is defined in multiple files: Interact.hs
                                                 Interact.hs``

I therefore searched on stack overflow and found the answers here (stack ghci with error module ‘main:Main’ is defined in multiple files:) which seem relevant.

However, unfortunately, they are undecipherable for the uninitiate, taking for granted concepts that I do not have at my disposal. For example, what are the following two sentences even suggesting?

I would run Stack with --verbose and see how GHCi is being invoked, and double-check the package.yaml and generated Cabal file. (If you edit your question to include that, we may be able to offer more specific help with it.)

I don't know what it means to check a package or a generated Cabal file (nor what a generated cabal file in). There is not definition of what is meant by 'invoked'.

I'm sure that the answers in the link above are very useful to those who already possess the requisite concepts. But to the uninitiated, they don't help.

Can someone please provide answers which clarify the particular questions I have above, so that I can understand the information provided in stack ghci with error module ‘main:Main’ is defined in multiple files:?


I typed stack --verbose into the terminal and this produced

 Missing: COMMAND|FILE

Usage: stack [--help] [--version] [--numeric-version] [--hpack-     numeric-version]
         [--docker*] [--nix*] ([--verbosity VERBOSITY] | [-v|--verbose] |
         [--silent]) [--[no-]time-in-log] [--stack-root STACK-ROOT]
         [--work-dir WORK-DIR] [--[no-]system-ghc] [--[no-]install-ghc]
         [--arch ARCH] [--ghc-variant VARIANT] [--ghc-build BUILD]
         [-j|--jobs JOBS] [--extra-include-dirs DIR] [--extra-lib-dirs DIR]
         [--with-gcc PATH-TO-GCC] [--with-hpack HPACK]
         [--[no-]skip-ghc-check] [--[no-]skip-msys] [--local-bin-path DIR]
         [--[no-]modify-code-page] [--[no-]allow-different-user]
         [--[no-]dump-logs] [--resolver RESOLVER] [--compiler COMPILER]
         [--[no-]terminal] [--color WHEN] [--terminal-width INT]
         [--stack-yaml STACK-YAML] COMMAND|FILE
1 Answers

You gave GHC the same file twice. GHC will automatically try finding a file by adding appropriate file extensions, so when you gave it Interact it found Interact.hs once, then you gave it the same file again.

I'm not sure what you were trying to achieve with your command. If you are trying to add a directory called Interact that GHC will search for modules, you want ghc -iInteract Interact.hs. If you are trying to name the binary that GHC outputs, you want ghc -o Interact Interact.hs (but that would be the default name anyway, so in that case you might as well just use ghc Interact.hs).

The stack documentation is probably irrelevant to you since you are using ghc directly.

Related