Haskell
Overview
Haskell is a purely functional language, especially suited for robust web applications.
There are many ways to write web applications in Haskell, from raw WAI to full-stack frameworks like Yesod, simple libraries like scotty or type-safe solutions like servant.
Configure your Haskell application
Mandatory configuration
Be sure that:
- you have pushed in master branch
- you listen on
0.0.0.0, on the port inPORT - you have one and only one binary target in your
.cabalfile - your project has a
stack.yamlfile
The steps ran in order are:
stack setupstack install --only-dependenciesstack install./<path>/my-exe(or the contents ofCC_RUN_COMMAND)
The executable built by stack build (or the command you specify) must start a web server listening on 0.0.0.0, on the port in PORT.
For instance, a minimal scotty application can look like this:
| |
Dependencies
Make sure to list all your dependencies in your .cabal file.
For the example above, you need:
| |
Cached dependencies
You can enable dependencies caching by adding the CC_CACHE_DEPENDENCIES=true.
It is enabled by default only for rust and haskell applications.
To disable dependencies caching completely, you can remove the CC_CACHE_DEPENDENCIES environment variable or by setting it to false.
To fully remove cached dependencies, you have to rebuild your application from scratch.
You can select rebuild and restart from the console or launch clever restart --without-cache with the Clever Tools CLI.
Custom run command
If you need to run a custom command (or just pass options to the binary built by stack), you can specify it through the CC_RUN_COMMAND environment variable.
For instance, for a hakyll website, you can define:
CC_RUN_COMMAND='~/.local/bin/site server --host 0.0.0.0 --port $PORT'To access environment variables from your code, just get them from the environment with getEnv :: String -> IO String in System.Environment.
If some environment variables are critical to your application, here is an approach you can use:
| |
This loads the environment variable in your main function and tests it. This way, the application will refuse to start with an helpful error message if MY_VAR is not defined.
Specify Stack package target
You may have several packages in your application which can be time consuming when building them, if you don’t want to build every packages you can target a package by using the CC_HASKELL_STACK_TARGET environment variable.
CC_HASKELL_STACK_TARGET="mypackage"