Difference between revisions of "How to write a Haskell program"
DonStewart (talk | contribs) (details on hosting) |
(added example cabal and link to monad transformer tutorial) |
||
Line 44: | Line 44: | ||
Use [http://haskell.org/cabal Cabal]. |
Use [http://haskell.org/cabal Cabal]. |
||
+ | === Example Setup === |
||
+ | Create a file called Setup.lhs with these contents: |
||
+ | <haskell> |
||
+ | #!/usr/bin/env runhaskell |
||
+ | |||
+ | > import Distribution.Simple |
||
+ | > main = defaultMain |
||
+ | |||
+ | </haskell> |
||
+ | Writing the setup file this way allows it to be executed directly by unix shells. |
||
+ | |||
+ | === Example cabal file for Executables === |
||
+ | Create the file myproject.cabal following this example: |
||
+ | <pre> |
||
+ | Name: MyProject |
||
+ | Version: 0.1 |
||
+ | License: BSD3 |
||
+ | Author: Your Name |
||
+ | Build-Depends: base |
||
+ | Synopsis: Example Cabal Executable File |
||
+ | |||
+ | Executable: myproj |
||
+ | Main-Is: Main.hs |
||
+ | Other-Modules: Foo |
||
+ | </pre> |
||
+ | |||
+ | === Example cabal file for Libraries === |
||
+ | Create the file myproject.cabal following this example: |
||
+ | <pre> |
||
+ | Name: MyProj |
||
+ | Version: 0.1 |
||
+ | License: BSD3 |
||
+ | Author: Your Name |
||
+ | Build-Depends: base |
||
+ | Synopsis: Example Cabel Library File |
||
+ | Exposed-Modules: MyProject.Foo |
||
+ | </pre> |
||
== Documentation == |
== Documentation == |
||
Line 55: | Line 92: | ||
Monad transformers are very useful for programming in the large, |
Monad transformers are very useful for programming in the large, |
||
− | encapsulating state, and controlling side effects. |
+ | encapsulating state, and controlling side effects. To learn more about this approach, try [http://uebb.cs.tu-berlin.de/~magr/pub/Transformers.en.html Monad Transformers Step by Step]. |
== Publicity == |
== Publicity == |
Revision as of 03:22, 30 October 2006
A guide to the best practice for creating a new Haskell project or program.
Structure
The basic structure of a new Haskell project can be adopted from HNop, the minimal Haskell project.
Licenses
Library code for the base libraries must be BSD licensed. Otherwise, it is your call. Choose a licence (inspired by this). Check licence of things you use, both other Haskell packages and C libraries. Use same as related where possible. Haskell community is split into 2 camps, roughly, those who release everything under BSD, and GPLers. We recommend avoiding LGPL, due to cross module optimisation issues.
Revision control
Use Darcs unless you hve a specific reason not to. Almost all new Haskell projects are released under Darcs, and this benefits everyone -- a set of common tools increases productivity, and you're more likely to get patches.
Advice:
- Tag each release
- Make sure you also release tarballs, darcs dist can do this automatically
Hosting
Source can be hosted on darcs.haskell.org (currently you need to email Simon Marlow to do this). Also, haskell.org itself has some user accounts available. Finally, there is SourceForge and other online/free sites.
Web page
Create a web page documenting your project! An easy way to do this is to add a project specific page to the Haskell wiki
Build system
Use Cabal.
Example Setup
Create a file called Setup.lhs with these contents:
#!/usr/bin/env runhaskell
> import Distribution.Simple
> main = defaultMain
Writing the setup file this way allows it to be executed directly by unix shells.
Example cabal file for Executables
Create the file myproject.cabal following this example:
Name: MyProject Version: 0.1 License: BSD3 Author: Your Name Build-Depends: base Synopsis: Example Cabal Executable File Executable: myproj Main-Is: Main.hs Other-Modules: Foo
Example cabal file for Libraries
Create the file myproject.cabal following this example:
Name: MyProj Version: 0.1 License: BSD3 Author: Your Name Build-Depends: base Synopsis: Example Cabel Library File Exposed-Modules: MyProject.Foo
Documentation
Use Haddock.
Testing
Pure code can be tested using QuickCheck. Impure code with HUnit.
Program structure
Monad transformers are very useful for programming in the large, encapsulating state, and controlling side effects. To learn more about this approach, try Monad Transformers Step by Step.
Publicity
The best code in the world is meaningless if nobody knows about it:
- Announce your project releases to haskell@haskell.org! This ensure it will then make it into the Haskell Weekly News. To be doubly sure, you should CC the release to the HWN editor
- Blog about it, on Planet Haskell
- Write about it on your blog
- Then email the Planet Haskell maintainer (ibid on #haskell) the RSS feed url for your blog
- Add your library or tool to the Libraries and tools page, under the relevant category, so people can find it.