Skip to content

Instantly share code, notes, and snippets.

@atmantree atmantree/README.markdown
Last active Aug 6, 2018

Embed
What would you like to do?
Gabriel Gonzalez: How to create a new Haskell project

Gabriel Gonzalez: How to create a new Haskell project

source: https://www.youtube.com/watch?v=ZJvHOpMnvpE


  • Haskell Stack

  • to install haskell stack curl -sSL https://get.haskellstack.org/ | sh

  • in a minimal project the simplest files looks like

Main.hs

main :: IO ()
main = putStrLn "Hello, world!"

hello.cabal

name: package_name
version: 0.0.1
build-type: Simple

executable hello
    main-is: Main.hs
    build-depends: base < 5

Setup.hs

import Distribution.Simple
main = defaultMain

Then you write cabal build and the program compiles into the dist/ folder. To run the program you can use:

  • ./dist/build/hello/hello or
  • cabal run

In order to make this proyect stack aware, we need to add a stack.yaml file in the same directory.

stack.yaml

resolver: lts-8.8
packages:
- .

(I add a line for cabal-version: >= 1.2 to my hello.cabal file because stack complains about it)

  • Cabal is for managing packages

  • Stack is for managing projects

  • take a look to the turtle package on hackage (http://hackage.haskell.org/package/turtle)

  • in stack it use the resolver to select which version to choose. (example for the lts-8.8 resolver: https://www.stackage.org/lts-8.8/cabal.config)

  • you can make cabal resolve dependencies from a stack resolver coping the resolver cabal.config to the root of the project.

  • if you want to use a dependency stored in your filesystem you can use (stack.yaml file):

resolver: lts-8.8
packages:
- .
- location: /home/carlos/my_library
  extra-dep: true
  • if you want to use a dependency stored in github you can use (stack.yaml file):
resolver: lts-8.8
packages:
- .
- location: 
  git: https://github.com/Gabriel439/Haskell-Turtle-Library.git
  commit: e000a88d2c9f21809ce3e56963ab9cf8d3f31082
  • you can create projects using stack from templates

  • stack templates gives you the list of templates included

  • stack new project_name TEMPLATE-NAME creates your project from the template.

  • you can make stack to be aware of the source files changes using stack test --file-watch, if you change any file, this will rebuild and retest the project everytime you save.

  • take a look to Test.DocTest (minute 22:21)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.