Skip to content

Instantly share code, notes, and snippets.

@lparolari
Last active January 7, 2020 21:17
Show Gist options
  • Select an option

  • Save lparolari/37787a8ebea056b29ad89be7846fb249 to your computer and use it in GitHub Desktop.

Select an option

Save lparolari/37787a8ebea056b29ad89be7846fb249 to your computer and use it in GitHub Desktop.
# hpack package file
name: <APP-NAME>
version: <VERSION>
github: "<YOUR-USERNAME>/<APP-NAME>"
license: <LICENSE>
author: "<YOUR-NAME>"
maintainer: "<YOUR-EMAIL>"
copyright: "<YEAR> <YOUR-NAME>"
extra-source-files:
- README.md
- CHANGELOG.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/<YOUR-GITHUB-USERNAME>/<APP-NAME>#readme>
ghc-options: -Wall
dependencies:
- base >= 4.7 && < 5
library:
source-dirs: src
exposed-modules:
- <APP-PACKAGES>
executables:
reci-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- <APP-PACKAGES>
tests:
reci-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- <APP-PACKAGES>
- hspec

Setup Haskell Project

Requirements:

Folder structure

The project has the following file structure

  • app: contains application example and/or application main
  • src: contains application (or library) sources
  • test: contains application tests

Hpack Setup

Hpack Hpack is a format for Haskell packages.

Hpack generates a .cabal file from the package.yaml file. So, you need to create a package.yaml file (see this example or the attached file)

All options for cabal file can be found here.

Run

hpack

to build the cabal file.

Stack Setup

Stack is a build tool for Haskell projects.

Setup stack with

stack init

and add to the packages section the root directory of the project.

Run stack with

# build the package
stack build

# run application
stack run

# run tests
stack test

Cabal

Run

cabal install

to install project dependencies.

Test Folder

In the test folder create a file named Spec.hs with the following content

{-# OPTIONS_GHC -F -pgmF hspec-discover #-}

Then create a folder test/APP-PACKAGE. This will contains all your tests for that package.

Src Folder

In the src folder create a file with the same name as your package. This will expose main functions. In the src folder can be created another folder with the name of package that contains other sources file related to your package.

App Folder

Create a file Main.hs with the following content

module Main where
    
    main :: IO ()
    main = do 
        putStrLn "Welcome!"
        # write here your code

Author

Luca Parolari <[email protected]>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment