Skip to content

onepunchtech/haskell-project-example

Repository files navigation

haskell-project-example

A follow along project for Haskell fundamentals workshop. Emphasizes practical solutions in Haskell, and covers the range of concepts needed to use Haskell in industry.

Setup

To ensure you have a working system, make sure you can run stack run You should see the string someFunc as the output

Choose one of the following options

Nix Flake

  1. Install Nix
  2. Enable nix flakes experimental feature
  3. cd haskell-project-example
  4. nix develop
  5. stack run
  6. Globally install haskell-language-server
  7. Ensure editor has lsp client
  8. Follow editor specific instructions on setting up lsp client and haskell-language-server

Nix Flake + Direnv

Direnv loads the project shell environment when you cd into the directory. Combined with nix this allows reproducibility and eases dev setup. It allows declaring all global dependencies (especially dev dependencies) within the project as executable code rather than documentation.

  1. Install Nix
  2. Enable nix flakes experimental feature
  3. Install Direnv
  4. cd haskell-project-example
  5. echo "use flake" > .envrc
  6. direnv allow
  7. stack run
  8. Ensure editor has direnv extension installed. This ensures that the editor picks up dev tools like haskell-language-server. The below are examples, not necessarily recommendations

Stack

If you prefer not to use nix then using stack works as usual. In this case you can set up editor tools globally.

  1. stack build
  2. stack run
  3. Globally install haskell-language-server
  4. Ensure editor has lsp client
  5. Follow editor specific instructions on setting up lsp client and haskell-language-server

ENVIRONMENT SETUP

export ALPACAKEY=${fill_me_in}
export ALPACASECRET=${fill_me_in}
export LD_LIBRARY_PATH=$PWD/number-munch/target/debug:$LD_LIBRARY_PATH

Profiling

Reference for rts options

https://downloads.haskell.org/~ghc/9.0.1/docs/html/users_guide/profiling.html

  • example useful commands
  • time profiling
    stack --profile run --rts-options -p
    
    # get allocation in bytes for each cost centre
    stack --profile run --rts-options -pa
    
    # get heap profile based on cost centres
    stack --profile run --rts-options -hc
    
    # get heap profile based on types
    stack --profile run --rts-options -hy
    
    # heap profiling produces .hp file. Convert it to postscript with hp2ps
    hp2ps -c -e540 ./api.hp
    
    # For memory issues it is sometimes useful to limit heap or stack size
    
    +RTS -M4m -RTS
    
        

State machine testing & property based testing

Must watch video

About

Haskell workshop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published