Skip to content

Instantly share code, notes, and snippets.

@CarstenKoenig
Created August 8, 2017 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarstenKoenig/56b5321dd10cbfb88efdcba1e9a382b8 to your computer and use it in GitHub Desktop.
Save CarstenKoenig/56b5321dd10cbfb88efdcba1e9a382b8 to your computer and use it in GitHub Desktop.
stack quick-example

1. Getting Stack on Ubuntu

I would actually use the installer script:

sudo curl -sSL https://get.haskellstack.org/ | sh

but an older version is on official sources as well (better to the upgrade after)

sudo apt install haskell-stack
stack upgrade

2. Update package list

stack update

3. let's just get a simple tempalte

stack new HelloHaskell scotty-hello-world
cd HelloHaskell

this will download a simple web-server example (really vanilla - no fancy folder setup, tests or anything)

4. get the env. up

stack setup

this will get GHC and everything it needs to build the project (the cd above is important) - usually you only have to do this once (as long as you don't switch to a higher LTS snapshot version that comes with a different GHC-version)

5. Build it

stack build

this will start downloading the dependencies and compile everything - and this can take some time and will take every resource it can get - maybe we have to do something here - but on a desktop this is no problem and after a while you should have it build

(btw: this is caching dependencies on your local system - so on a developer machine this will run really quick for your second project)

6. test run

stack exec HelloHaskell

if you browse to localhost:3000 you should see Scotty, me up! (Ctrl-C when you are done to exit the server)

7. get it to a reasonable place

stack install

this will copy the executable to ~/.local/bin which is usually in the path

8. clean up

stack clean

that will remove most of the temp files - if you want you can do

rm  .stack-work -rf

to remove the rest as well (but most of the downloaded compiled stuff is in ~/.stack still)

9. works still

and it should still work if started

~/.local/bin/HelloHaskell

that's it

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