How to ghc "Finding imports" on stack

68 views
Skip to first unread message

Gianluca Sant

unread,
Jul 21, 2020, 5:55:48 AM7/21/20
to haskell-stack
Hi everyone, 
I'm trying to add Stack to my existing Haskell project. however, when I try to build it with Stack I get the following error 

    File name does not match module name:
    Saw: ‘MyModuleName’
    Expected: ‘ MyModuleName. MyModuleName
  |
4 | module MyModuleName

This is happening because I've structured the project in the following way. 

+ root
 + MyModuleName
  |---- MyModuleName
  | Main.hs

With GHC you can easily fix this issue by using "-i" flag - e.g. "-iMyModuleName". Therefore I was wondering if I can define the same "search path" on Stack.

Thanks in advance
Gianluca

Michael Snoyman

unread,
Jul 21, 2020, 6:07:04 AM7/21/20
to haskell-stack

You can use source-dirs (in hpack/package.yaml) or hs-source-dirs (in cabal files) to specify the directory. Though standard practice these days in Haskell projects is to put the code in an src directory.

 

For more information on hpack settings and some examples, check out: https://github.com/sol/hpack#readme

Gianluca Sant

unread,
Jul 21, 2020, 6:12:08 AM7/21/20
to Michael Snoyman, haskell-stack
Hi, thanks for the reply - I will give a try. 

Though standard practice these days in Haskell projects is to put the code in an src directory.

Yes, I put it in the src folder - sorry if I haven’t provided a real project structure - basically what I have is 

+root
  | +app
    | Main.hs
  | +src
    | + MyModule
      | MyModule.hs

so, I’m following standard approach for a Stack project


-- 
You received this message because you are subscribed to the Google Groups "haskell-stack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-stac...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-stack/1d5f9491-85bc-45a2-9ddb-a03e0aaf0b06n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages