2
votes

Hello i am trying to use a module inside another module but it seems it just won't work.I tried updating the cabal file,stack,i reinstalled the platform,ghc and everything and it just won't let it import modules.I tried adding in the cabal file both other-modules and home-modules section ..to no effect.What could be the problem?

Modules:

module Test where


    test::IO()
    test=do
        elem<-getLine
        print elem


module Main where

import Test

main :: IO ()
main = do
  putStrLn "hello world"

Cabal-build renders this error:

$ cabal build

Resolving dependencies...
Configuring console-0.1.0.0...
Warning: To use the 'default-language' field the package needs to specify at
least 'cabal-version: >= 1.10'.
Preprocessing executable 'console' for console-0.1.0.0..
Building executable 'console' for console-0.1.0.0..

<no location info>: warning: [-Wmissing-home-modules]
    These modules are needed for compilation but not listed in your .cabal file's other-modules: Test

<no location info>: warning: [-Wmissing-home-modules]
    These modules are needed for compilation but not listed in your .cabal file's other-modules: Test

When i build with Stack i get this error:

C:\<path>\Main.hs:4:1: error:
    Failed to load interface for `Test'
    Use -v to see a list of the files searched for.
Failed, modules loaded: none.
H>>= :module + *Main

Cabal file:

 name:                console
version:             0.1.0.0
-- synopsis:
-- description:
homepage:            https://github.com/githubuser/console#readme
license:             BSD3
license-file:        LICENSE
author:              Bercovici Adrian Simon
maintainer:          [email protected]
copyright:           2018 Bercovici Adrian Simon
category:            Web
build-type:          Simple
cabal-version:       >=1.2
extra-source-files:  README.md


Executable console
  hs-source-dirs:      src
  main-is:             Main.hs
  default-language:    Haskell2010

  build-depends:       base                  >= 4.7    && < 5
  other-modules:       Test
1

1 Answers

3
votes

The other-modules: directive must go inside the Executable console stanza.