Skip to content

Instantly share code, notes, and snippets.

@DarinM223
Last active January 26, 2021 03:33
Show Gist options
  • Save DarinM223/80ea11b33be38997e0fa180334617fc1 to your computer and use it in GitHub Desktop.
Save DarinM223/80ea11b33be38997e0fa180334617fc1 to your computer and use it in GitHub Desktop.
Haskell/Purescript/Lisp tooling

Haskell

Package manager

The main package manager to use in Haskell is Cabal. Make sure that the Cabal version that you are using is at least 3.0. Then build, repl, install, etc will use the upgraded v2-style versions that work with minimal problems.

Documentation

Have you ever tried :doc on something only for GHC to tell you that -haddock wasn't enabled? The way to fix this is to add -haddock to every installed cabal package. Edit ~/.cabal/config and uncomment the ghc-options: option under program-default-options and add the -haddock flag. The resulting file should look like:

program-default-options
  ghc-options: -haddock

The next time you build, GHC will rebuild your packages with haddock enabled. Then you will be able to look at documentation with :doc.

Repl

To add modules into the repl, type :m +module or import module. To remove modules from the repl, type :m -module. Qualified imports can be removed this way also. When loading modules, if you prefix the module with * (like :load *module) then you can autocomplete all functions and qualified imports as if you were in that module.

Hoogle

The best way I've found to use hoogle is to just run hoogle generate and have it build all the installed packages. The option for only building local packages is too complex to use and doesn't seem to capture all of them. To look at the documentation of the first Hoogle result run hoogle query -i. To help constrain the result to a specific module, run hoogle Module.function.

If you use stack instead of cabal then you can generate local hoogle databases and query them. Use stack hoogle to generate a local database and stack hoogle query to query it.

Ghcid

The best way to use ghcid is to add a .ghcid file in your cabal project that looks like this:

--restart=project.cabal -c cabal v2-repl

That way, when you modify your cabal file ghcid will automatically rebuild your project.

Git repository packages

If you want packages that depend on git repositories add a cabal.project file that looks like this in the same folder as the project:

packages: .

source-repository-package
  type: git
  location: github url
  tag: commit hash

Options for source-repository-package are here.

Purescript

Package manager

The package manager for Purescript is Spago. To install it, clone the git repository and run stack install (this works without needing a newer version of glibc).

Docs

To generate documentation for your project and its dependencies run spago docs. Then you can search the documentation with spago search.

Pscid

Pscid is the Purescript version of Ghcid, and later versions of it also work with Spago. When updating dependencies, you can go into Pscid and type b to trigger a build and r to restart Pscid.

Lisp

Package manager

The package manager to use is quicklisp. To create a new project, you need to have sbcl and quicklisp installed. Then inside sbcl run:

(ql:quickload "cl-project")
(cl-project:make-project #P"./path-to-project/root/")

The project should be in the path ~/common-lisp so that quicklisp can detect it. Then to load your project in slime, type (ql:quickload :project-name). Then you can evaluate files inside your project with all the dependencies included.

Looking up documentation

In order to store documentation for the core of lisp offline, you have to download HyperSpec. Do this by running this command inside sbcl:

(ql:quickload "clhs")

Then inside emacs with slime if you type C-c C-d h it will open the browser to the offline documentation for the symbol your cursor is currently on.

Emacs bindings

  • M-x slime: Start slime
  • C-x d: Enter dired (to change files)
  • C-x o: Switch buffers in split window (switching between slime and your code)
  • C-x b: Switch buffers (allows you to switch back to the code window if the debug window obscured it)
  • C-c C-z: Open SLIME REPL (useful when a REPL accidentally gets closed but SLIME is still active)
  • C-M-x: Evaluate lisp expression
  • C-c C-c: Recompile a lisp function (useful for fixing the code on the fly)
  • C-c C-r: Evaluate selected region of text (useful for readtable stuff like array infix operations)
  • C-c C-k: Evaluate whole file
  • C-c M-t: Trace function at cursor
  • C-c M-m: Expand macro
  • C-c Shift-t: Open SLIME trace dialog
  • C-c Shift-i: Inspect value at cursor
  • M-.: Jump to function definition

Debugger

Add a (break) statement to enter the debugger. Then you can choose a stack frame and press r to restart that stack frame or s to step in that stack frame.

Pressing e in a stack frame allows you to evaluate arbitrary code in a stack frame. This allows you to modify local parameters in a stack frame.

Pressing i on a local parameter opens up the parameter's value in the inspector.

Pressing v on a stack frame jumps to the source code where the exception was created.

Racket

Emacs bindings

  • C-h m: Shows all keybindings
  • C-M-y: Insert unicode lambda symbol
  • C-c C-d: View documentation for symbol on cursor
  • C-c C-k: Load file
  • C-M-x: Send expression to REPL
  • C-c C-r: Send region to REPL
  • C-c C-e r: Expand macro region with stepper

Python

Mypy

Run pip install mypy inside env terminal to install mypy for a project.

Pycharm mypy

Install the dropbox mypy plugin, go to Mypy Terminal (should be next to Python console), right click the plugin window, and select Configure plugin..., then type in ./venv/bin into PATH suffix (for Linux).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment