Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 323
HHC Avatar asked Jan 20 '13 02:01

HHC


People also ask

How do you create a project stack?

To build your project, Stack uses a project-level configuration file, named stack. yaml , in the root directory of your project as a sort of blueprint. That file contains a reference, called a resolver, to the snapshot which your package will be built against.

Where do you put the Haskell code?

If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt. Alternatively, if you are on Windows, you may choose WinGHCi in the Start menu. And you are presented with a prompt.


2 Answers

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?
like image 135
Davorak Avatar answered Sep 20 '22 03:09

Davorak


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

like image 25
James McMahon Avatar answered Sep 20 '22 03:09

James McMahon