Skip to content

frankhjung/haskell-scrapbook

Repository files navigation

Haskell Scrapbook

Haskell workflow

A collection of short scripts testing functions and techniques.

The project is built using Cabal.

To coordinate various build tasks I use GNU Make.

Links

Haddock API documentation is available on:

(See also benchmark reports below.)

Quick Start

These examples are meant to be run using runhaskell(1) or runghc.

The reason they won't link is because I've added them to their own module, and have not yet gotten around to build an über main yet. The idea was really to test an run code snippets quickly without having to bother with compiling and linking a main module.

The build uses GNU make to check source files.

Build

Use a local Cabal project profile, cabal.project with:

packages: scrapbook.cabal
with-compiler: /home/frank/.ghcup/bin/ghc-8.10.7

This will use the specified GHC, which can be different from the system version.

Build using GNU Make:

make setup default

Format

Format and style code using:

make format

This runs:

SRC=$(find * -name '*.hs')
cabal-fmt --inplace Scrapbook.cabal
stylish-haskell --inplace ${SRC}

Check

To only perform code checks, run:

make check

This runs tags and lint:

SRC=$(find * -name '*.hs')
hasktags --ctags --extendedctag ${SRC}
cabal check --verbose
hlint --cross --color --show ${SRC}

Repl

To start a REPL with the project loaded, use:

stack repl

Using Cabal also works for the REPL:

cabal repl

Test

Test using GNU Make:

make test

This runs:

cabal test --test-show-details=always

To re-run a failed test, call:

cabal test --test-show-details=direct --test-option=--match --test-option='/Weekday/test weekday type/capitalised head of string/'

Performance

The Criterion benchmark HTML reports can be generated using stack. They are available from GitHub, here:

To run individual benchmark:

cabal bench PolyDivisorsBench

Individual benchmarks can be reported as well by calling the benchmark executable and providing an output file. For example:

dist-newstyle/build/x86_64-linux/ghc-8.8.4/scrapbook-0.1.0/b/myfilterBench/build/myfilterBench/myfilterBench --output myfilter.html

Documentation

To generate Haddock for source:

cabal haddock --haddock-quickjump --haddock-hyperlink-source

ghcid

Notes on using ghcid.

Installing ghcid

cabal update
cabal install ghcid

Then copy executable to $HOME/.local/bin/.

Using ghcid

For example to monitor changes for one file app/Threads.hs call:

ghcid -l -c 'ghci -package stm app/Threads.hs'

If no errors, then the screen will report something like:

All good (1 module, at 21:28:27)

Alternatively, to monitor a couple of files:

ghcid -l src/Weekday.hs test/WeekdaySpec.hs

To monitor the entire project, use:

ghcid -l

Using ghcid in Vim

To monitor a couple of files (as per above):

:let g:ghcid_args="--lint src/Weekday.hs test/WeekdaySpec.hs"
:GhcidStart

To stop, call:

:GhcidStop

See also vim-ghcid plugin.

ghcup

When editing using Visual Studio Code, use GHCup.

To show available software versions:

ghcup tui

To show current installation:

ghcup list

Example output:

$ ghcup list -c installed
   Tool  Version  Tags                      Notes
✔✔ ghc   9.6.7    recommended,base-4.18.3.0 hls-powered
✔✔ cabal 3.12.1.0 recommended
✔✔ hls   2.10.0.0 latest,recommended
✔✔ stack 3.5.1    latest
✔✔ ghcup 0.1.50.2 latest,recommended

About

Haskell scrapbook of test scripts.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •