Skip to content

Jacobbishopxy/studies-haskell

Repository files navigation

Studies Haskell

Haskell Installation

  1. curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

  2. [MacOS] copy the entire file (cat ~/.ghcup/env) into ~/.zshrc

  3. ghcup tui open a GUI to install the rest part, (i for install; u for uninstall; s for set and enable)

  4. [optional] set ghcup mirror: https://mirrors.ustc.edu.cn/help/ghcup.html

  5. [optional] set cabal mirror: https://mirrors.ustc.edu.cn/help/hackage.html#cabal

Cabal

User Guide

Lib Construction and Installation

  1. cabal init to create a .cabal file

  2. touch Setup.hs and put:

    #!/usr/bin/env runhaskell
    import Distribution.Simple
    main = defaultMain
  3. runghc Setup configure --prefix=$HOME --user: config to user level's repo

  4. runghc Setup build: build package

  5. runghc Setup install: install package

  6. ghc-pkg list: list all installed packages

  7. ghc-pkg unregister: remove a package

VsCode Setting

settings.json (use ghcup tui to get ghc & hls versions):

  ...
  "haskell.manageHLS": "GHCup",
  "haskell.toolchain": {
    "ghc": "recommended", // otherwise, use specific version, or "latest"
    "hls": "recommended",
    "cabal": "recommended",
    "stack": "recommended"
  },
  "haskell.serverEnvironment": {
    "PATH": "${HOME}/.ghcup/bin:$PATH"
  },
  ...

Project Management

See implicit-hie

cd your-stack-or-cabal-package
stack install implicit-hie # or cabal install implicit-hie
gen-hie > hie.yaml

Test

  • compile a single file: ghc --make capslocker.hs

Misc

  • While using GHCI, it might show libgmp.so: cannot open shared object file: No such file or directory, and to solve this we can apt install libgmp-dev.

  • libtinfo.so: cannot open shared object file: No such file or directory: apt install libtinfo-dev

  • Cabal-fmt installation: cabal install cabal-fmt

Cheatsheets

Study Material

Exercises

Reference