A collection of short scripts testing functions and techniques.
The project is built using Cabal.
To coordinate various build tasks I use GNU Make.
Haddock API documentation is available on:
(See also benchmark reports below.)
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.
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 defaultFormat and style code using:
make formatThis runs:
SRC=$(find * -name '*.hs')
cabal-fmt --inplace Scrapbook.cabal
stylish-haskell --inplace ${SRC}To only perform code checks, run:
make checkThis runs tags and lint:
SRC=$(find * -name '*.hs')
hasktags --ctags --extendedctag ${SRC}
cabal check --verbose
hlint --cross --color --show ${SRC}To start a REPL with the project loaded, use:
stack replUsing Cabal also works for the REPL:
cabal replTest using GNU Make:
make testThis runs:
cabal test --test-show-details=alwaysTo 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/'The Criterion benchmark HTML reports can be generated using stack. They are available from GitHub, here:
- Criterion benchmarks:
To run individual benchmark:
cabal bench PolyDivisorsBenchIndividual 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.htmlTo generate Haddock for source:
cabal haddock --haddock-quickjump --haddock-hyperlink-sourceNotes on using ghcid.
cabal update
cabal install ghcidThen copy executable to $HOME/.local/bin/.
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.hsTo monitor the entire project, use:
ghcid -lTo 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.
When editing using Visual Studio Code, use GHCup.
To show available software versions:
ghcup tuiTo show current installation:
ghcup listExample 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