How to install Ormolu in Vim 8 and format when saving?

Install Ormolu:

stack install ormolu --resolver=lts-15.10

Ensure the created binary is in your $PATH.

Install Vim plugin:

git -C ~/.vim/pack/plugins/start clone https://github.com/sdiehl/vim-ormolu

Add autocmd to ~/.vimrc:

autocmd BufWritePre *.hs :call RunOrmolu()