How to structure a Haskell project?

I'm currently trying to do a Haskell project using the Test Driven Development methodology. In Java, we can create a nicely structured project containing src and bin folders, then there are main and test folders for unit testing with JUnit. I was just wondering is there a standard way to get such a structure in Haskell? A folder for source a folder for binary, and in the source folder two folders one for testing one for main source.


The modern answer to this is to use The Haskell Tool Stack. This will structure the project for you using sane defaults.


My reference is alway Structure of a Haskell project and How to write a Haskell program which spell out some defaults which the community more or less seems to follow. It has worked well for me so far but my projects have not been very large as of yet.

What is suggested in Structure of a Haskell project sounds similar to what you have outlined in your post with a few minor modifications like the testing folder is in the same directory as the src folder.

Edit:

cabal init will generate a minimal amount for you including the cabal file with relevant dependencies if you have a any files with imports at least. It is a great start but only part of what you are looking for.

Ideally as a project grows the cabal file and directory hierarchy would be automatically kept up to date, I am unaware of any tool made public that will do this though. It is on my maybe one day list as I am sure it s for many others.

-odir and -hidir can be used with ghc to put the *.o and *.hi files in separate directories. You can read more in GHC user guide's section on separate compilation)

Edit2:

Other relevant/overlapping posts:

  • Basic Structure of a Haskell Program
  • Haskell module naming conventions
  • Large-scale design in Haskell?
  • 链接地址: http://www.djcxy.com/p/42872.html

    上一篇: 静态类型检查的设计模式

    下一篇: 如何构建一个Haskell项目?