<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.7.3">Jekyll</generator><link href="https://mendo.zone/feed.xml" rel="self" type="application/atom+xml" /><link href="https://mendo.zone/" rel="alternate" type="text/html" /><updated>2019-07-21T21:59:29-06:00</updated><id>https://mendo.zone/</id><title type="html">mendo.zone</title><subtitle>Welcome to John Mendonça's blog where we discuss Web Development, Linux Administration, and Functional Programming.</subtitle><author><name>John Mendonça</name></author><entry><title type="html">Neovim for Haskell Development</title><link href="https://mendo.zone/fun/neovim-setup-haskell/" rel="alternate" type="text/html" title="Neovim for Haskell Development" /><published>2018-06-30T15:27:28-06:00</published><updated>2018-06-30T15:27:28-06:00</updated><id>https://mendo.zone/fun/neovim-setup-haskell</id><content type="html" xml:base="https://mendo.zone/fun/neovim-setup-haskell/">&lt;p&gt;Here’s how I setup neovim or vim 8 to be a functional working environment.&lt;/p&gt;

&lt;!-- --&gt;

&lt;p&gt;The focus will be on Haskell, but many of the plugins here are useful for any language in both vim and neovim.&lt;/p&gt;

&lt;h2 id=&quot;limits-of-vim&quot;&gt;Limits of Vim&lt;/h2&gt;

&lt;p&gt;My vim config for PureScript had been working nicely for me this year, but my Haskell setup was lacking in features.&lt;/p&gt;

&lt;p&gt;I started working through &lt;a href=&quot;http://www.stephendiehl.com/posts/vim_2016.html&quot;&gt;Stephen Diehl’s vim article&lt;/a&gt;, adding plugins for autocompletion, snippets, and tab alignment.&lt;/p&gt;

&lt;p&gt;The features were now there, but performance in vim had gone down noticeably.  Opening a file for the first time would take about 4 seconds (as indicated by vim’s &lt;em&gt;profile&lt;/em&gt; feature).&lt;/p&gt;

&lt;p&gt;On top of that, vim does not support &lt;a href=&quot;https://hackage.haskell.org/package/intero&quot;&gt;Intero&lt;/a&gt;, which is supposed to be the &lt;em&gt;killer feature&lt;/em&gt; of Haskell on Emacs.  I thought maybe it was time to finally tackle the Emacs learning curve for the sake of Haskell development.&lt;/p&gt;

&lt;p&gt;Then I discovered there is &lt;a href=&quot;https://github.com/parsonsmatt/intero-neovim&quot;&gt;Intero support for neovim&lt;/a&gt;.  Also, some of the plugins I had just installed were intended first for neovim, and only worked in vim 8 through compatibility plugins.&lt;/p&gt;

&lt;p&gt;Surely neovim ought to have better performance for these plugins. Right? :thumbsup:&lt;/p&gt;

&lt;h2 id=&quot;how-i-vim&quot;&gt;How I Vim&lt;/h2&gt;

&lt;p&gt;Before I go over the plugins I have chosen to use, I want to show how I use git to save my vim setup for use on multiple machines.&lt;/p&gt;

&lt;p&gt;First of all, I load my plugins using &lt;a href=&quot;https://github.com/tpope/vim-pathogen&quot;&gt;Pathogen&lt;/a&gt;.  With Pathogen, you only have to download the plugin to &lt;code class=&quot;highlighter-rouge&quot;&gt;~/.vim/bundle/&lt;/code&gt; and it will be loaded when vim starts.&lt;/p&gt;

&lt;p&gt;My &lt;code class=&quot;highlighter-rouge&quot;&gt;.vim&lt;/code&gt; folder is a git repo that I push to GitHub, so I can access it when setting up a new machine.  Since most vim plugins can also be found on GitHub, I add them to this repo as &lt;a href=&quot;https://git-scm.com/book/en/v2/Git-Tools-Submodules&quot;&gt;git submodules&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd ~/.vim/bundle/
git submodule add https://github.com/neovimhaskell/haskell-vim.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The primary benefit here is that I can update all my plugins by updating submodules:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git submodule update --recursive --remote
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Downloading my &lt;code class=&quot;highlighter-rouge&quot;&gt;.vim&lt;/code&gt; repo on a new machine therefore requires the &lt;code class=&quot;highlighter-rouge&quot;&gt;--recursive&lt;/code&gt; option to also download submodules:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone --recursive https://github.com/johnmendonca/vimrc.git .vim
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The downside to this approach is that &lt;a href=&quot;https://stackoverflow.com/questions/1260748/how-do-i-remove-a-submodule#1260982&quot;&gt;removing submodules can be a pain&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;installing-neovim&quot;&gt;Installing neovim&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/neovim/neovim/wiki/Installing-Neovim&quot;&gt;Installing neovim&lt;/a&gt; depends on your system.&lt;/p&gt;

&lt;p&gt;In my case (&lt;em&gt;Linux Mint&lt;/em&gt;), there is no system package for neovim.  I followed the &lt;a href=&quot;https://github.com/neovim/neovim/wiki/Installing-Neovim#ubuntu&quot;&gt;installation instructions&lt;/a&gt; to install using the Ubuntu PPA.&lt;/p&gt;

&lt;p&gt;Start neovim by running:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nvim
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now with a fresh working install of neovim, we are ready to start setting it up.&lt;/p&gt;

&lt;h2 id=&quot;configuring-neovim&quot;&gt;Configuring neovim&lt;/h2&gt;

&lt;p&gt;The config file for neovim exists at &lt;code class=&quot;highlighter-rouge&quot;&gt;~/.config/nvim/init.vim&lt;/code&gt;, rather than &lt;code class=&quot;highlighter-rouge&quot;&gt;~/.vimrc&lt;/code&gt;.  If you want to use your existing vim config in neovim, &lt;a href=&quot;https://neovim.io/doc/user/nvim.html#nvim-from-vim&quot;&gt;you can do that&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First I copied over my basic &lt;code class=&quot;highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt; commands over to &lt;code class=&quot;highlighter-rouge&quot;&gt;~/.config/nvim/init.vim&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;syntax &lt;span class=&quot;k&quot;&gt;on&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;filetype&lt;/span&gt; plugin indent &lt;span class=&quot;k&quot;&gt;on&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; nocompatible
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;number&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; showmode
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; smartcase
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; smarttab
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; smartindent
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; autoindent
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; expandtab
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; shiftwidth&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; softtabstop&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; background&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dark&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; laststatus&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;colo&lt;/span&gt; darkblue
&lt;span class=&quot;k&quot;&gt;hi&lt;/span&gt; Keyword ctermfg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;darkcyan
&lt;span class=&quot;k&quot;&gt;hi&lt;/span&gt; Constant ctermfg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;5&lt;/span&gt;*
&lt;span class=&quot;k&quot;&gt;hi&lt;/span&gt; Comment ctermfg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;*
&lt;span class=&quot;k&quot;&gt;hi&lt;/span&gt; Normal ctermbg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;none
&lt;span class=&quot;k&quot;&gt;hi&lt;/span&gt; LineNr ctermfg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;darkgrey
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Some of these may be redundant in neovim.&lt;/p&gt;

&lt;h3 id=&quot;pathogen&quot;&gt;Pathogen&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/tpope/vim-pathogen&quot;&gt;Pathogen&lt;/a&gt; is the foundation for installing all plugins.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mkdir -p ~/.config/nvim/autoload
cd !$
wget https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In &lt;code class=&quot;highlighter-rouge&quot;&gt;~/.config/nvim/init.vim&lt;/code&gt; add:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;execute pathogen#infect&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now your plugins in &lt;code class=&quot;highlighter-rouge&quot;&gt;~/.config/nvim/bundle/&lt;/code&gt; should be loaded whenever neovim starts.&lt;/p&gt;

&lt;h2 id=&quot;plugins&quot;&gt;Plugins&lt;/h2&gt;

&lt;p&gt;I have shown above how to install a plugin as a git submodule, but the minimum that you need to install any plugin is to download it into your &lt;code class=&quot;highlighter-rouge&quot;&gt;bundle&lt;/code&gt; folder:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd ~/.config/nvim/bundle/
git clone https://github.com/neovimhaskell/haskell-vim.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is the same for all the plugins listed here.&lt;/p&gt;

&lt;p&gt;Let’s start with the most general purpose plugins and move to those specifically for Haskell.&lt;/p&gt;

&lt;h3 id=&quot;nerdtree&quot;&gt;NERDTree&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/scrooloose/nerdtree&quot;&gt;NERDTree&lt;/a&gt; will provide a vim split with your project folder structure that you can use to browse, create, delete, copy, or move files without typing out the full commands.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017/nerdtree.png&quot; alt=&quot;nerd tree window&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Install the plugin and modify your &lt;code class=&quot;highlighter-rouge&quot;&gt;init.vim&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&quot;Open NERDTree when nvim starts&lt;/span&gt;
autocmd &lt;span class=&quot;nb&quot;&gt;StdinReadPre&lt;/span&gt; * &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s:std_in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
autocmd &lt;span class=&quot;nb&quot;&gt;VimEnter&lt;/span&gt; * &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; argc&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; &lt;span class=&quot;p&quot;&gt;!&lt;/span&gt;exists&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;s:std_in&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;|&lt;/span&gt; NERDTree &lt;span class=&quot;p&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;endif&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&quot;Toggle NERDTree with Ctrl-N&lt;/span&gt;
map &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;NERDTreeToggle&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&quot;Show hidden files in NERDTree&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; NERDTreeShowHidden&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;ctrlpvim&quot;&gt;ctrlp.vim&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ctrlpvim/ctrlp.vim&quot;&gt;ctrlp.vim&lt;/a&gt; allows you to perform a fuzzy name search on the files within your project directory.  This brings the killer feature of Sublime Text into vim.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017/ctrlp_screen.png&quot; alt=&quot;control p window&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Simply install and restart nvim.  Now whenever you press &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;Ctrl-p&amp;gt;&lt;/code&gt; a new file search window should appear.&lt;/p&gt;

&lt;h3 id=&quot;grepper&quot;&gt;Grepper&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mhinz/vim-grepper&quot;&gt;Grepper&lt;/a&gt; performs text search throughout the files in your project.  I had previously used &lt;a href=&quot;https://github.com/mileszs/ack.vim&quot;&gt;ack.vim&lt;/a&gt; but it requires you to install the Perl tool &lt;code class=&quot;highlighter-rouge&quot;&gt;ack&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I don’t use text search in my work very often, and both of these plugins mess up my splits sometimes.  There are times when text search is critical though, and I wouldn’t be without a plugin like this.&lt;/p&gt;

&lt;p&gt;Grepper supports a variety of search tools, but the default works fine for me.  I bind the key command &lt;code class=&quot;highlighter-rouge&quot;&gt;\ga&lt;/code&gt; to search the entire project, and &lt;code class=&quot;highlighter-rouge&quot;&gt;\gb&lt;/code&gt; to search only the current buffer:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&quot;Use Grepper&lt;/span&gt;
nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;ga &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;Grepper&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;cr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;gb &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;Grepper &lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;buffer&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;cr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now you can search for the text “foo” throughout your project by typing the following in command mode:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;\gafoo&amp;lt;Enter&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;vim-tmux-navigator&quot;&gt;Vim Tmux Navigator&lt;/h3&gt;

&lt;p&gt;This one is for &lt;code class=&quot;highlighter-rouge&quot;&gt;tmux&lt;/code&gt; users only.  &lt;code class=&quot;highlighter-rouge&quot;&gt;tmux&lt;/code&gt; is useful when you’re working on a remote server and don’t want to worry about your &lt;code class=&quot;highlighter-rouge&quot;&gt;ssh&lt;/code&gt; session becoming disconnected.  It also allows you to split one terminal emulator into many terminal windows.&lt;/p&gt;

&lt;p&gt;I use both &lt;code class=&quot;highlighter-rouge&quot;&gt;tmux&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;vim&lt;/code&gt; window splits at the same time.  For example here is my screen while writing this page (using vim 8):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017/tmux_vim_screen.jpg&quot; alt=&quot;tmux and vim screen&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/christoomey/vim-tmux-navigator&quot;&gt;Vim Tmux Navigator&lt;/a&gt; allows you to move between both types of splits seamlessly using one set of key commands.  After this is setup you will be able to move between all splits using &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;Ctrl&amp;gt; + &amp;lt;h, j, k, l&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;These are the same keys for moving around within a vim document.  Now just hold &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;Ctrl&amp;gt;&lt;/code&gt; and you will be moving between splits.&lt;/p&gt;

&lt;p&gt;Configuration changes are needed for &lt;code class=&quot;highlighter-rouge&quot;&gt;tmux&lt;/code&gt;, add this to your &lt;code class=&quot;highlighter-rouge&quot;&gt;~/.tmux.conf&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Smart pane switching with awareness of Vim splits.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# See: https://github.com/christoomey/vim-tmux-navigator&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;is_vim&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ps -o state= -o comm= -t '#{pane_tty}' &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
    | grep -iqE '^[^TXZ ]+ +(&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;S+&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/)?g?(view|&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\.&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;?n?vim?x?(-wrapped)?)(diff)?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$'&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; C-h &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-shell&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$is_vim&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;send-keys C-h&quot;&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;&quot;select-pane -L&quot;&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; C-j &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-shell&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$is_vim&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;send-keys C-j&quot;&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;&quot;select-pane -D&quot;&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; C-k &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-shell&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$is_vim&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;send-keys C-k&quot;&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;&quot;select-pane -U&quot;&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; C-l &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-shell&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$is_vim&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;send-keys C-l&quot;&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;&quot;select-pane -R&quot;&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; C-&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-shell&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$is_vim&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;send-keys C-&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;select-pane -l&quot;&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-T&lt;/span&gt; copy-mode-vi C-h &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-pane&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-L&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-T&lt;/span&gt; copy-mode-vi C-j &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-pane&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-T&lt;/span&gt; copy-mode-vi C-k &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-pane&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-T&lt;/span&gt; copy-mode-vi C-l &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-pane&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt;
bind-key &lt;span class=&quot;nt&quot;&gt;-T&lt;/span&gt; copy-mode-vi C-&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-pane&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This plugin has worked well for me in vim, and does not require config changes if you use the default key bindings.&lt;/p&gt;

&lt;p&gt;Some people have problems getting this to work right with neovim.  There are some &lt;a href=&quot;https://github.com/christoomey/vim-tmux-navigator/issues&quot;&gt;outstanding issues&lt;/a&gt; with neovim that you should check if you have trouble.&lt;/p&gt;

&lt;p&gt;I encountered one of these issues, where &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;Ctrl-h&amp;gt;&lt;/code&gt; would not work in neovim inside tmux (the keypress registers as &lt;code class=&quot;highlighter-rouge&quot;&gt;Backspace&lt;/code&gt;).  The following change to &lt;code class=&quot;highlighter-rouge&quot;&gt;init.vim&lt;/code&gt; is a workaround:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&quot;Hack for neovim and vim-tmux-navigator&lt;/span&gt;
nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;BS&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;TmuxNavigateLeft&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;cr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously I had installed neovim through Nix, and had an issue caused by binary names used in Nix.  If you installed neovim though Nix, use my tmux config above and not the default from the plugin README.  There is a necessary &lt;a href=&quot;https://github.com/christoomey/vim-tmux-navigator/pull/171/files&quot;&gt;regex change&lt;/a&gt; for Nix binary support.&lt;/p&gt;

&lt;h3 id=&quot;vim-gitgutter&quot;&gt;vim-gitgutter&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/airblade/vim-gitgutter&quot;&gt;vim-gitgutter&lt;/a&gt; will show &lt;code class=&quot;highlighter-rouge&quot;&gt;git diff&lt;/code&gt; information in a column along the left edge of your file.  You will be able to see which lines are new or modified, and where lines have been removed.  It’s a little convenience that saves you a trip to the console.&lt;/p&gt;

&lt;p&gt;If you want to run even more git commands within your editor, check out &lt;a href=&quot;https://github.com/tpope/vim-fugitive&quot;&gt;fugitive.vim&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;haskell-ide&quot;&gt;Haskell IDE&lt;/h2&gt;

&lt;p&gt;Let’s look at the plugins that will allow us to turn neovim into a Haskell IDE.  Thanks to &lt;a href=&quot;http://www.stephendiehl.com/posts/vim_2016.html&quot;&gt;Stephen Diehl&lt;/a&gt; and &lt;a href=&quot;https://blog.jez.io/haskell-development-with-neovim/&quot;&gt;Jake Zimmerman&lt;/a&gt; for much of this information.&lt;/p&gt;

&lt;h3 id=&quot;haskell-vim&quot;&gt;haskell-vim&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/neovimhaskell/haskell-vim&quot;&gt;haskell-vim&lt;/a&gt; provides an alternative syntax highlighter, and options for indentation.  Here are my settings for &lt;code class=&quot;highlighter-rouge&quot;&gt;init.vim&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_classic_highlighting&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_case&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_let&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_where&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;6&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_before_where&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_after_bare_where&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_do&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_guard&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskell_indent_case_alternative&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:cabal_indent_section&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;intero&quot;&gt;Intero&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/parsonsmatt/intero-neovim&quot;&gt;Intero for Neovim&lt;/a&gt; will run a GHCi console process inside neovim, making it convenient to reload your files and enter expressions.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017/intero_screen.png&quot; alt=&quot;intero window&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This plugin uses &lt;code class=&quot;highlighter-rouge&quot;&gt;stack&lt;/code&gt; by default but can be &lt;a href=&quot;https://github.com/parsonsmatt/intero-neovim#using-a-custom-backend&quot;&gt;configured otherwise&lt;/a&gt;.  Another alternative is &lt;a href=&quot;https://github.com/owickstrom/neovim-ghci&quot;&gt;neovim-ghci&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The first time you open a Haskell file after installing the plugin, it will automatically open a split in vim and build &lt;code class=&quot;highlighter-rouge&quot;&gt;intero&lt;/code&gt; for your stack project.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/parsonsmatt/intero-neovim#example-configuration&quot;&gt;example configuration&lt;/a&gt; on the GitHub page is a good place to start, though I have the following setup for my needs:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&quot; Automatically reload on save&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;BufWritePost&lt;/span&gt; *&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;hs InteroReload

&lt;span class=&quot;c&quot;&gt;&quot; Lookup the type of expression under the cursor&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nmap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;Plug&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;InteroGenericType
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nmap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;T &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;Plug&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;InteroType
&lt;span class=&quot;c&quot;&gt;&quot; Insert type declaration&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;ni &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroTypeInsert&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&quot; Show info about expression or type under the cursor&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroInfo&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&quot; Open/Close the Intero terminal window&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;nn &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroOpen&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;nh &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroHide&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&quot; Reload the current file into REPL&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;nf &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroLoadCurrentFile&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&quot; Jump to the definition of an identifier&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;ng &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroGoToDef&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&quot; Evaluate an expression in REPL&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;ne &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroEval&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&quot; Start/Stop Intero&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;ns &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroStart&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;nk &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroKill&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&quot; Reboot Intero, for when dependencies are added&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;nr &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroKill&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroOpen&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&quot; Managing targets&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&quot; Prompts you to enter targets (no silent):&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;nt &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroSetTargets&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With this config, Intero will start automatically and I can open a terminal split using &lt;code class=&quot;highlighter-rouge&quot;&gt;\nn&lt;/code&gt;, then hide it again using &lt;code class=&quot;highlighter-rouge&quot;&gt;\nh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Using the terminal in neovim is a little strange.  Move to the split and press &lt;code class=&quot;highlighter-rouge&quot;&gt;i&lt;/code&gt; to enter &lt;em&gt;Terminal&lt;/em&gt; mode (not insert mode) and you can enter commands into the REPL.  Exit terminal mode by pressing &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;Ctrl-\&amp;gt; &amp;lt;Ctrl-n&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The author of the plugin has &lt;a href=&quot;https://github.com/parsonsmatt/intero-neovim/issues/97&quot;&gt;an example keybinding&lt;/a&gt; to make exiting terminal mode a little more intuitive.  I have adapted his example to use the split movement keys we setup in the &lt;code class=&quot;highlighter-rouge&quot;&gt;tmux&lt;/code&gt; section:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&quot; Ctrl-{hjkl} for navigating out of terminal panes&lt;/span&gt;
tnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;\&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;h&lt;/span&gt;
tnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;\&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;j&lt;/span&gt;
tnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;\&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;k&lt;/span&gt;
tnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;\&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;C&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You still need to hit &lt;code class=&quot;highlighter-rouge&quot;&gt;i&lt;/code&gt; to enter terminal mode.  Alternatively, you can use &lt;code class=&quot;highlighter-rouge&quot;&gt;:InteroEval&lt;/code&gt; to enter an expression in the REPL without moving panes at all.&lt;/p&gt;

&lt;p&gt;With my config, you can type &lt;code class=&quot;highlighter-rouge&quot;&gt;\ne2+2&amp;lt;Enter&amp;gt;&lt;/code&gt; to execute &lt;code class=&quot;highlighter-rouge&quot;&gt;2+2&lt;/code&gt; in the REPL without ever leaving your file.&lt;/p&gt;

&lt;h4 id=&quot;testing&quot;&gt;Testing&lt;/h4&gt;

&lt;p&gt;When you are writing tests for a Stack project, and want to use Intero to load and run your test code, you have to first change the target using &lt;code class=&quot;highlighter-rouge&quot;&gt;:InteroSetTargets&lt;/code&gt;.  The reason for this is that a Stack project may have different dependencies for a library or executable versus your test code.  So, unless you change to the testing target, dependencies like &lt;code class=&quot;highlighter-rouge&quot;&gt;hspec&lt;/code&gt; will not be loaded and available to Intero.&lt;/p&gt;

&lt;p&gt;When I am working on a spec I want to save my file and run the spec without moving to the console.  I can bind the expression &lt;code class=&quot;highlighter-rouge&quot;&gt;hspec spec&lt;/code&gt; to the command &lt;code class=&quot;highlighter-rouge&quot;&gt;\nb&lt;/code&gt; using &lt;code class=&quot;highlighter-rouge&quot;&gt;:InteroSend&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&quot; Run the spec in the current file&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;nb&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;InteroSend hspec spec&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;neomake&quot;&gt;Neomake&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/neomake/neomake&quot;&gt;Neomake&lt;/a&gt; allows us to run programs against our files and project.  By default for Haskell files, neomake will use &lt;code class=&quot;highlighter-rouge&quot;&gt;ghc-mod&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;hlint&lt;/code&gt;, and &lt;code class=&quot;highlighter-rouge&quot;&gt;hdevtools&lt;/code&gt; to check your files&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017/neomake_screen.png&quot; alt=&quot;neomake in effect&quot; /&gt;&lt;/p&gt;

&lt;p&gt;These programs need to be installed first:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;stack install ghc-mod hlint hdevtools
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Neomake is an alternative for &lt;a href=&quot;https://github.com/vim-syntastic/syntastic&quot;&gt;Syntastic&lt;/a&gt;.  Add this to your &lt;code class=&quot;highlighter-rouge&quot;&gt;init.vim&lt;/code&gt; to have checks ran against your file every time you save it:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;call&lt;/span&gt; neomake#configure#automake&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'w'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Neomake will highlight lines of code with issues, and the command &lt;code class=&quot;highlighter-rouge&quot;&gt;:lopen&lt;/code&gt; will open a window listing the issues.  If you want to have this window open automatically use this config:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:neomake_open_list&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Intero uses Neomake to do syntax checks on your files.  I prefer to use Intero only and none of the others.  This config will disable the default checkers:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:neomake_haskell_enabled_makers&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now only Intero will perform syntax checks when a file is saved, and we can still manually run the other checks if desired:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;:Neomake ghcmod
:Neomake hlint
:Neomake hdevtools
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;ghcmod-vim&quot;&gt;ghcmod-vim&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/eagletmt/ghcmod-vim&quot;&gt;ghcmod-vim&lt;/a&gt; allows you to use &lt;code class=&quot;highlighter-rouge&quot;&gt;ghc-mod&lt;/code&gt; commands in vim.  You can display the type of the item under the cursor, or expand a function definition for all the cases of a data type.&lt;/p&gt;

&lt;p&gt;You have to also install &lt;a href=&quot;https://github.com/Shougo/vimproc.vim&quot;&gt;vimproc&lt;/a&gt;.  This plugin requires an extra installation step depending on your system.  On linux:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;bundle/vimproc.vim/
make
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Since there is overlap between this plugin and Intero, I only use a couple commands:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nmap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;mc &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;GhcModSplitFunCase&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nmap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;ms &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;GhcModSigCodegen&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;vim-hindent--vim-stylishask&quot;&gt;vim-hindent / vim-stylishask&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/alx741/vim-hindent&quot;&gt;vim-hindent&lt;/a&gt; and &lt;a href=&quot;https://github.com/alx741/vim-stylishask&quot;&gt;vim-stylishask&lt;/a&gt; are pretty-printers that will reformat your source code to match standard style guides.  The programs need to be installed first:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;stack install hindent stylish-haskell
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The resulting code looks very nice! :bowtie:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017/hindent.png&quot; alt=&quot;hindent in effect&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I have set these tasks to only be run manually:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:hindent_on_save&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;ph &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;Hindent&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:stylishask_on_save&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;ps&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;Stylishask&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;These plugins can also process your file every time you save.  Just replace a &lt;code class=&quot;highlighter-rouge&quot;&gt;0&lt;/code&gt; with a &lt;code class=&quot;highlighter-rouge&quot;&gt;1&lt;/code&gt; above on the printer you want to use.&lt;/p&gt;

&lt;h3 id=&quot;tabular&quot;&gt;Tabular&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/godlygeek/tabular&quot;&gt;Tabular&lt;/a&gt; allows you to align characters in multiple rows.  For example, this can align the &lt;code class=&quot;highlighter-rouge&quot;&gt;=&lt;/code&gt; in a series of assignments, or the &lt;code class=&quot;highlighter-rouge&quot;&gt;-&amp;gt;&lt;/code&gt; in a set of pattern matches.&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;Tabularize /&lt;span class=&quot;p&quot;&gt;=&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;-&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;Tabularize /&lt;span class=&quot;p&quot;&gt;-&amp;gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;Tabularize /&lt;span class=&quot;p&quot;&gt;,&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;# &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;Tabularize /#&lt;span class=&quot;p&quot;&gt;-}&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Pressing &lt;code class=&quot;highlighter-rouge&quot;&gt;\=&lt;/code&gt; inside the following code block:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;area&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Point&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;area&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Square&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;area&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Rectangle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;will reformat it into:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;area&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Point&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;area&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Square&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;area&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Rectangle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;vim-hsimport&quot;&gt;vim-hsimport&lt;/h3&gt;

&lt;p class=&quot;notice--info&quot;&gt;Note: as of my last update, &lt;code class=&quot;highlighter-rouge&quot;&gt;hdevtools&lt;/code&gt; does not work with the most recent versions of GHC.  This plugin will not work until &lt;code class=&quot;highlighter-rouge&quot;&gt;hdevtools&lt;/code&gt; is updated.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/dan-t/vim-hsimport&quot;&gt;vim-hsimport&lt;/a&gt; will insert import statements for the identifier under the cursor.  It is based on &lt;code class=&quot;highlighter-rouge&quot;&gt;hsimport&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;hdevtools&lt;/code&gt; which must be installed first:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;stack install hsimport hdevtools
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It also requires a globally accessible &lt;code class=&quot;highlighter-rouge&quot;&gt;ghc&lt;/code&gt; command.  Using this plugin with Stack resulted in an error for me, until I added the location of &lt;code class=&quot;highlighter-rouge&quot;&gt;ghc&lt;/code&gt; to my system path.  It is a bit of a hack, but I added the following to my &lt;code class=&quot;highlighter-rouge&quot;&gt;.bashrc&lt;/code&gt; file:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Put GHC on the path globally&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;GHC_PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;stack path | &lt;span class=&quot;nb&quot;&gt;grep &lt;/span&gt;compiler-bin | sed &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'s/compiler-bin: //'&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PATH&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$GHC_PATH&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Also kill any &lt;code class=&quot;highlighter-rouge&quot;&gt;hdevtools&lt;/code&gt; processes, so it will restart :disappointed_relieved::&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pkill hdevtools
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once installed, you can add insert statements for entire modules or individual symbols:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;ims &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;HsimportSymbol&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell nnoremap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;silent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;imm &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;HsimportModule&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;deopletenvim&quot;&gt;deoplete.nvim&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;&quot;&gt;deoplete&lt;/a&gt; is a general framework for completions in neovim.  It requires installation of a Python 3 module:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip3 install neovim
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Vim 8 requires a couple &lt;a href=&quot;https://github.com/Shougo/deoplete.nvim#requirements&quot;&gt;extra plugins&lt;/a&gt; for compatibility.&lt;/p&gt;

&lt;p&gt;Activate deoplete when nvim starts:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&quot; Use deoplete.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:deoplete&lt;/span&gt;#enable_at_startup &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now when you are typing, you should see a completion menu recommending other words from your file.  You can select them with the arrow keys and hit &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;Enter&amp;gt;&lt;/code&gt; to insert your choice.&lt;/p&gt;

&lt;p&gt;We’ll add a couple more plugins to make this more useful.&lt;/p&gt;

&lt;h3 id=&quot;supertab&quot;&gt;supertab&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ervandew/supertab&quot;&gt;supertab&lt;/a&gt; will allow us to choose a completion with the &lt;code class=&quot;highlighter-rouge&quot;&gt;Tab&lt;/code&gt; key instead of the arrow keys.&lt;/p&gt;

&lt;p&gt;Setup the &lt;code class=&quot;highlighter-rouge&quot;&gt;Tab&lt;/code&gt; key to call vim’s omnifunc:&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:SuperTabDefaultCompletionType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&amp;lt;c-x&amp;gt;&amp;lt;c-o&amp;gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;neco-ghc&quot;&gt;neco-ghc&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/eagletmt/neco-ghc&quot;&gt;neco-ghc&lt;/a&gt; uses &lt;code class=&quot;highlighter-rouge&quot;&gt;ghc-mod&lt;/code&gt; to fill the autocomplete menus with useful Haskell options.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017/deco-ghc-screen.png&quot; alt=&quot;neco-ghc completions screen&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-vim highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&quot; Disable haskell-vim omnifunc&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:haskellmode_completion_ghc&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&quot; neco-ghc&lt;/span&gt;
autocmd &lt;span class=&quot;nb&quot;&gt;FileType&lt;/span&gt; haskell &lt;span class=&quot;k&quot;&gt;setlocal&lt;/span&gt; omnifunc&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;necoghc#omnifunc 
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;g:necoghc_enable_detailed_browse&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;snipmate--ultisnips&quot;&gt;SnipMate / UltiSnips&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/garbas/vim-snipmate&quot;&gt;SnipMate&lt;/a&gt; and &lt;a href=&quot;https://github.com/sirver/UltiSnips&quot;&gt;UltiSnips&lt;/a&gt; will allow you to paste snippets into your documents.  If you have any sort of boilerplate code that you use often, these plugins can save you some time.&lt;/p&gt;

&lt;p&gt;Which plugin to choose depends on what snippets file you want to use.  I have not used these enough to have a preference.&lt;/p&gt;

&lt;p&gt;Here are some haskell snippets to pick from:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/sdiehl/haskell-vim-proto/blob/master/vim/snippets/haskell.snippets&quot;&gt;sdiehl/haskell-vim-proto&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/dag/vim2hs/blob/master/UltiSnips/haskell.snippets&quot;&gt;dag/vim2hs&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/honza/vim-snippets/blob/master/snippets/haskell.snippets&quot;&gt;honza/vim-snippets&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Thank you for joining me on this tour of great open source software.&lt;/p&gt;

&lt;p&gt;If you like what you’ve seen here, you can download and use my neovim configuration:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/johnmendonca/nvim&quot;&gt;johnmendonca/nvim&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I am happy with this setup, as it delivers the performance and usability improvements I had hoped for.&lt;/p&gt;

&lt;p&gt;If you find that this article has missed something, or if you have any other suggestions, please contact me on Twitter at &lt;a href=&quot;https://twitter.com/johnmendonca&quot;&gt;@johnmendonca&lt;/a&gt;.&lt;/p&gt;</content><author><name>John Mendonça</name></author><category term="vim" /><category term="haskell" /><summary type="html">Here’s how I setup neovim or vim 8 to be a functional working environment.</summary></entry><entry><title type="html">How to Define a Function in Haskell and PureScript</title><link href="https://mendo.zone/fun/functions-haskell-purescript/" rel="alternate" type="text/html" title="How to Define a Function in Haskell and PureScript" /><published>2017-12-17T11:56:56-07:00</published><updated>2017-12-17T11:56:56-07:00</updated><id>https://mendo.zone/fun/functions-haskell-purescript</id><content type="html" xml:base="https://mendo.zone/fun/functions-haskell-purescript/">&lt;p&gt;Defining functions in these languages is quite concise, and there are a few different forms that you’ll want to be able to recognize.
&lt;!-- --&gt;&lt;/p&gt;

&lt;h2 id=&quot;basic-functions&quot;&gt;Basic Functions&lt;/h2&gt;

&lt;p&gt;A function with parameters can be defined using only whitespace and the equals sign:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;name param1 param2 = ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Any time there are multiple names on the left side on an equals sign, the first is the function name and the remaining are parameter names.&lt;/p&gt;

&lt;p&gt;The body of the function is on the right hand side of the equals sign.  Here is a simple function that combines two string to make a greeting:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello name = &quot;Hello, &quot; ++ name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Calling a function is done simply by giving the name with its arguments separated by spaces:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello &quot;you&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The result of this expression is &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;Hello, you&quot;&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;types&quot;&gt;Types&lt;/h3&gt;

&lt;p&gt;Specifying the type of your function is optional if the compiler can infer it.  Adding type signatures is recommended because they are very informative when reading code.  Here is our definition including the type signature:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello :: String -&amp;gt; String
hello name = &quot;Hello, &quot; ++ name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When you define a function this way, the type of the right hand expression should match the return type of the function.  Here are some example expressions listed with their types:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello                  :: String -&amp;gt; String
hello &quot;friend&quot;         :: String
&quot;Hello, &quot; ++ &quot;friend&quot;  :: String
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;functions-as-values&quot;&gt;Functions as Values&lt;/h2&gt;

&lt;p&gt;It is also possible to define functions where the parameter names are not listed on the left:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello :: String -&amp;gt; String
hello = ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This works anytime the type of the expression on the right is &lt;code class=&quot;highlighter-rouge&quot;&gt;String -&amp;gt; String&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Unlike many other languauges, functions themselves are values and can be used any place other values can.&lt;/p&gt;

&lt;p&gt;Once a function has been defined, its name can be used to refer to it as a value:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;greeting :: String -&amp;gt; String
greeting = hello
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this case, we are not calling &lt;code class=&quot;highlighter-rouge&quot;&gt;hello&lt;/code&gt; but referring to the function itself.  All values including functions are immutable, and never change once created.  &lt;code class=&quot;highlighter-rouge&quot;&gt;hello&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;greeting&lt;/code&gt; are now just two names referring to the same function value.&lt;/p&gt;

&lt;h2 id=&quot;lambdas&quot;&gt;Lambdas&lt;/h2&gt;

&lt;p&gt;A lambda expression lets us create an anonymous function value:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;\param1 param2 -&amp;gt; ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There is no equals sign here, and this function does not have a name.  This evaluates to a function with two parameters.  Using our example:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello :: String -&amp;gt; String
hello = \name -&amp;gt; &quot;Hello, &quot; ++ name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The value on the right of the equals is a complete function of type &lt;code class=&quot;highlighter-rouge&quot;&gt;String -&amp;gt; String&lt;/code&gt;.  This &lt;code class=&quot;highlighter-rouge&quot;&gt;hello&lt;/code&gt; function works exactly the same as our first example.&lt;/p&gt;

&lt;h2 id=&quot;pattern-matching&quot;&gt;Pattern Matching&lt;/h2&gt;

&lt;p&gt;Sometimes your function will have different behavior based on the value of your arguments.  In other languages, you would use constructs like &lt;code class=&quot;highlighter-rouge&quot;&gt;switch&lt;/code&gt;,  &lt;code class=&quot;highlighter-rouge&quot;&gt;case&lt;/code&gt;, or &lt;code class=&quot;highlighter-rouge&quot;&gt;if&lt;/code&gt; inside your function to handle this.&lt;/p&gt;

&lt;p&gt;Pattern matching allows us to redefine our function for specific cases rather than create branching structures:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello &quot;Alice&quot; = &quot;Hi Alice!&quot;
hello &quot;Bob&quot;   = &quot;Hey Bob&quot;
hello name    = &quot;Hello, &quot; ++ name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Anytime the argument data matches a specific case we have defined, that function body will be used instead.  The last case uses a parameter instead of concrete data, so it will handle any case not matched above it.&lt;/p&gt;

&lt;p&gt;Never omit the final catch-all definition, as this will result in a compiler error or a program that could possibly crash.&lt;/p&gt;

&lt;p&gt;Pattern matching is also very useful for destructuring lists and algebraic data types.  Many functions that take these types as parameters will use pattern matching to extract values out of the data structure.  I will not go into this more here but will show an example:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data Shape = Circle Float
           | Rectangle Float Float           

shapeArea :: Shape -&amp;gt; Float
shapeArea (Circle r)      = 3.1415 * r * r
shapeArea (Rectangle h w) = h * w
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;guards&quot;&gt;Guards&lt;/h2&gt;

&lt;p&gt;Guards allow different function bodies based on any true or false condition.  Pattern matching is limited to literal data structures, and guards can be used with any expression of type &lt;code class=&quot;highlighter-rouge&quot;&gt;Boolean&lt;/code&gt;.  Here is the same example from above:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello name
  | name == &quot;Alice&quot; = &quot;Hi Alice!&quot;
  | name == &quot;Bob    = &quot;Hey Bob&quot;
  | otherwise       = &quot;Hello, &quot; ++ name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;otherwise&lt;/code&gt; is just a synonym for &lt;code class=&quot;highlighter-rouge&quot;&gt;true&lt;/code&gt;, you should always have a catch-all guard to ensure all code paths are defined.&lt;/p&gt;

&lt;h2 id=&quot;operators&quot;&gt;Operators&lt;/h2&gt;

&lt;p&gt;Operators like &lt;code class=&quot;highlighter-rouge&quot;&gt;++&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;$&amp;gt;&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;*&amp;gt;&lt;/code&gt;, or &lt;code class=&quot;highlighter-rouge&quot;&gt;*&lt;/code&gt; are just functions that default to infix notation.  Alphanumeric functions use prefix notation.  We will not go deep into operator precedence and defining operators here, but you will want to recognize when an operator is being used.&lt;/p&gt;

&lt;p&gt;Operators are usually written in infix notation, where the first argument comes before the function name:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2 + 3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Parentheses allow you to use an operator in prefix notation like a regular function:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;(+) 2 3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The operator with parentheses is also the official name of the function, if you want to use it as a value:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;addNumbers = (+)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Regular functions use prefix notation by default but can used in an infix position by using ticks.  The following are equivalent:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;addNumbers 2 3
2 `addNumbers` 3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;This has been a quick rundown of function forms in Haskell and PureScript.  Hopefully any code examples you see will now be a little more clear!  We have only scratched the surface of some very useful features, and you now have what you need to dig into these topics on your own.&lt;/p&gt;</content><author><name>John Mendonça</name></author><category term="haskell" /><category term="purescript" /><summary type="html">Defining functions in these languages is quite concise, and there are a few different forms that you’ll want to be able to recognize.</summary></entry><entry><title type="html">Beginner’s Haskell: Creating Bitmap Images</title><link href="https://mendo.zone/fun/beginners-haskell-bitmap-images/" rel="alternate" type="text/html" title="Beginner's Haskell: Creating Bitmap Images" /><published>2017-12-13T13:25:50-07:00</published><updated>2017-12-13T13:25:50-07:00</updated><id>https://mendo.zone/fun/beginners-haskell-bitmap-images</id><content type="html" xml:base="https://mendo.zone/fun/beginners-haskell-bitmap-images/">&lt;p&gt;Let’s use the library &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt; in Haskell to easily display images.  We’ll explore the types used by &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt; and create a bitmap using &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt;.
&lt;!-- --&gt;&lt;/p&gt;

&lt;h2 id=&quot;project-setup&quot;&gt;Project Setup&lt;/h2&gt;

&lt;p&gt;We’ll use &lt;code class=&quot;highlighter-rouge&quot;&gt;stack&lt;/code&gt; for this project, which I recommend for anyone starting out with haskell.&lt;/p&gt;

&lt;p class=&quot;notice--info&quot;&gt;Download and Install &lt;a href=&quot;https://docs.haskellstack.org/en/stable/README/&quot;&gt;Stack&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run this command to create a directory with your new project:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;stack new gloss-bitmaps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run the following to confirm the project is working.  This may take some time when downloading GHC and libraries.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd gloss-bitmaps/
stack setup
stack build
stack exec gloss-bitmaps-exe
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This should print the text &lt;code class=&quot;highlighter-rouge&quot;&gt;someFunc&lt;/code&gt;.  If this is not working at this point, you will need to troubleshoot your stack installation or setup.&lt;/p&gt;

&lt;h2 id=&quot;finding-documentation&quot;&gt;Finding Documentation&lt;/h2&gt;

&lt;p&gt;Usage examples for Haskell libraries can be hard to find, and we often must rely on library documentation.  I would like to explore the process for finding API documentation, using &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt; as an example.&lt;/p&gt;

&lt;p&gt;Searching for “graphics libraries in Haskell” turns up this list: &lt;a href=&quot;https://wiki.haskell.org/Applications_and_libraries/Graphics&quot;&gt;Applications and libraries/Graphics&lt;/a&gt;.  The &lt;a href=&quot;https://wiki.haskell.org/&quot;&gt;HaskellWiki&lt;/a&gt; is often a good source for high level overviews like this.&lt;/p&gt;

&lt;p&gt;Through search results and listings, I see &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt; is a popular library and has a high-level API with examples.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://hackage.haskell.org/package/gloss&quot;&gt;top level hackage page for gloss&lt;/a&gt; does not have any information about basic usage.  This page is what you will usually find when searching for a Haskell library.  We need to dig into the module documentation.&lt;/p&gt;

&lt;p&gt;There is a &lt;code class=&quot;highlighter-rouge&quot;&gt;Modules&lt;/code&gt; section on the hackage page, let’s click the top level module for more information: &lt;a href=&quot;https://hackage.haskell.org/package/gloss-1.11.1.1/docs/Graphics-Gloss.html&quot;&gt;Graphics.Gloss&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This page works as a starting point.  We have a basic example and API documentation for the top level functions.  There are many other modules to explore from the main hackage page when we need to use them.&lt;/p&gt;

&lt;p&gt;Let’s start with the example in the &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt; documentation.&lt;/p&gt;

&lt;h2 id=&quot;basic-gloss&quot;&gt;Basic &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;First we will need to add &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt; as a dependency for our project.  Edit the &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss-bitmaps.cabal&lt;/code&gt; file and add it to the &lt;code class=&quot;highlighter-rouge&quot;&gt;library&lt;/code&gt; section:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
library
  hs-source-dirs:      src
  exposed-modules:     Lib
  build-depends:       base &amp;gt;= 4.7 &amp;amp;&amp;amp; &amp;lt; 5&lt;b&gt;
                     , gloss&lt;/b&gt;
  default-language:    Haskell2010
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Stack uses &lt;code class=&quot;highlighter-rouge&quot;&gt;hpack&lt;/code&gt; in its default project template to specify project settings.  We will only use the cabal file in this article, so please delete the &lt;code class=&quot;highlighter-rouge&quot;&gt;hpack&lt;/code&gt; config before building:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rm package.yaml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Edit the library source file &lt;code class=&quot;highlighter-rouge&quot;&gt;src/Lib.hs&lt;/code&gt;, and add the example code from the &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt; documentation:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;module Lib
    ( someFunc
    ) where

&lt;b&gt;import Graphics.Gloss&lt;/b&gt;

someFunc :: IO ()
someFunc = &lt;b&gt;display (InWindow &quot;Nice Window&quot; (200, 200) (10, 10)) white (Circle 80)&lt;/b&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Rebuild and run:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;stack build
stack exec gloss-bitmaps-exe
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The program should open a new window with a drawing of a circle.&lt;/p&gt;

&lt;h3 id=&quot;display&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;display&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;Let’s take a look at the type for the &lt;code class=&quot;highlighter-rouge&quot;&gt;display&lt;/code&gt; function, found in the module documentation:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;display&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Display&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;-- Display mode.&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Color&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;-- Background color.&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Picture&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;-- The picture to draw.&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IO&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In our example, the first argument to &lt;code class=&quot;highlighter-rouge&quot;&gt;display&lt;/code&gt; is:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;(InWindow &quot;Nice Window&quot; (200, 200) (10, 10))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This must have the type &lt;code class=&quot;highlighter-rouge&quot;&gt;Display&lt;/code&gt;.  Sure enough, we can confirm this in the documentation (and in the source code).  The data type &lt;code class=&quot;highlighter-rouge&quot;&gt;Display&lt;/code&gt; has two constuctors:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kr&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Display&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;-- Display in a window with the given name, size and position.&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;InWindow&lt;/span&gt;   &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;-- Display full screen.&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FullScreen&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Experiment with this and see if you can change the window size or display the image in full screen.&lt;/p&gt;

&lt;p&gt;The second parameter of &lt;code class=&quot;highlighter-rouge&quot;&gt;display&lt;/code&gt; is very straight forward.  It is the background color for our display.  In our case we are passing &lt;code class=&quot;highlighter-rouge&quot;&gt;white&lt;/code&gt;, which is a value from the &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt; library.&lt;/p&gt;

&lt;p&gt;The third parameter is of type &lt;code class=&quot;highlighter-rouge&quot;&gt;Picture&lt;/code&gt;.  We are passing the value &lt;code class=&quot;highlighter-rouge&quot;&gt;(Circle 80)&lt;/code&gt;.  From this we can infer that &lt;code class=&quot;highlighter-rouge&quot;&gt;Circle&lt;/code&gt; is a constructor which takes a number (the radius) and returns a &lt;code class=&quot;highlighter-rouge&quot;&gt;Picture&lt;/code&gt; of a circle.&lt;/p&gt;

&lt;h2 id=&quot;drawing-bitmaps&quot;&gt;Drawing Bitmaps&lt;/h2&gt;

&lt;p&gt;We’ve got a lot going for us already with just this one line of code.  We know if we have a &lt;code class=&quot;highlighter-rouge&quot;&gt;Picture&lt;/code&gt;, we have a way to display it.  Instead of using drawing functions like &lt;code class=&quot;highlighter-rouge&quot;&gt;circle&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;line&lt;/code&gt;, let’s find out how to make a bitmap &lt;code class=&quot;highlighter-rouge&quot;&gt;Picture&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A bitmap image is basically just a big list of pixels.  A 100x100 image would have 10,000 pixels.  Each pixel is a 32-bit &lt;code class=&quot;highlighter-rouge&quot;&gt;RGBA&lt;/code&gt; value.  The value is broken into 4 bytes, one each for red, green, blue, and alpha (transparency).&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;RGBA&lt;/code&gt; system allows us to specify any color and transparency.  For example, in CSS if you wanted a nearly transparent purple, you could say:&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;.25&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;bitmaps-in-gloss&quot;&gt;Bitmaps in &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;We need to dig through the documentation again to find out how to create a bitmap &lt;code class=&quot;highlighter-rouge&quot;&gt;Picture&lt;/code&gt;.  The top level module has a reference to a &lt;code class=&quot;highlighter-rouge&quot;&gt;Bitmap&lt;/code&gt; module so let’s check that out: &lt;a href=&quot;https://hackage.haskell.org/package/gloss-1.11.1.1/docs/Graphics-Gloss-Data-Bitmap.html&quot;&gt;Graphics.Gloss.Data.Bitmap&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Please note if you want to view the source code: this code is imported from another package called &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss-rendering&lt;/code&gt;: &lt;a href=&quot;https://hackage.haskell.org/package/gloss-rendering-1.11.1.1/docs/Graphics-Gloss-Rendering.html&quot;&gt;Graphics.Gloss.Rendering&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;There are some promising looking functions here, the best one for us uses &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;bitmapOfByteString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
                   &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
                   &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;BitmapFormat&lt;/span&gt;
                   &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ByteString&lt;/span&gt;
                   &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;
                   &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Picture&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;-- Copy a ByteString of RGBA data into a bitmap with the given width and height.&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;-- The boolean flag controls whether Gloss should cache the data between frames for speed.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt; is a basic Haskell type to represent binary data without any assumption of encoding.  There are also functions to create bitmaps from a &lt;code class=&quot;highlighter-rouge&quot;&gt;BMP&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;ForeignPtr Word8&lt;/code&gt;.  These other functions might be useful if we were loading an image from a file or from memory created by another program.&lt;/p&gt;

&lt;p class=&quot;notice--warning&quot;&gt;Since we are just generating one image in Haskell, &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt; should be the easiest to work with.  We are not going to worry about performance this time.&lt;/p&gt;

&lt;p&gt;Looking at the type and documentation for &lt;code class=&quot;highlighter-rouge&quot;&gt;bitmapOfByteString&lt;/code&gt;, we can see the first two &lt;code class=&quot;highlighter-rouge&quot;&gt;Int&lt;/code&gt; parameters are for the width and height of the image.  Let’s say those will both be 100 for a 100x100 image.&lt;/p&gt;

&lt;p&gt;The last parameter is a &lt;code class=&quot;highlighter-rouge&quot;&gt;Bool&lt;/code&gt; to turn on caching provided by &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss&lt;/code&gt;.  Since we are just drawing one image and not changing it, this feature will not matter.  Let’s just pass &lt;code class=&quot;highlighter-rouge&quot;&gt;True&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This remaining two parameters have the types &lt;code class=&quot;highlighter-rouge&quot;&gt;BitmapFormat&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt;.  We know the &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt; will hold the binary data for our image, so the &lt;code class=&quot;highlighter-rouge&quot;&gt;BitmapFormat&lt;/code&gt; must describe how that data should be formatted.&lt;/p&gt;

&lt;h3 id=&quot;bitmapformat&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;BitmapFormat&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;We just need to lookup &lt;code class=&quot;highlighter-rouge&quot;&gt;BitmapFormat&lt;/code&gt; in our module documentation:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data BitmapFormat
        = BitmapFormat 
        { rowOrder    :: RowOrder
        , pixelFormat :: PixelFormat }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This type uses Haskell record syntax, we can simplify this for clarity:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data BitmapFormat = BitmapFormat RowOrder PixelFormat
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;BitmapFormat&lt;/code&gt; is just a combination of &lt;code class=&quot;highlighter-rouge&quot;&gt;RowOrder&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;PixelFormat&lt;/code&gt;.  Let’s look at these:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;data RowOrder
        = TopToBottom 
        | BottomToTop

data PixelFormat
        = PxRGBA | PxABGR
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;These two settings say how our binary image data will be interpreted.  &lt;code class=&quot;highlighter-rouge&quot;&gt;RowOrder&lt;/code&gt; determines if the first bytes in our data are for the top or bottom row in our image.  &lt;code class=&quot;highlighter-rouge&quot;&gt;PixelFormat&lt;/code&gt; similarly determines what order the bytes in each pixel should be.&lt;/p&gt;

&lt;p&gt;We can choose any format as long as our image data matches.  Let’s use this as our format:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;BitmapFormat TopToBottom PxRGBA
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now all we need is our bitmap data in a &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt;.  Let’s update our library code to include everything we have looked at.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;module Lib
    ( someFunc
    ) where

import Graphics.Gloss

&lt;b&gt;bitmapData = undefined

ourPicture :: Picture
ourPicture = bitmapOfByteString 100 100 (BitmapFormat TopToBottom PxRGBA) bitmapData True&lt;/b&gt;

someFunc :: IO ()
someFunc = display (InWindow &quot;Nice Window&quot; (200, 200) (10, 10)) white &lt;b&gt;ourPicture&lt;/b&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This code will compile but will not run due to the presence of &lt;code class=&quot;highlighter-rouge&quot;&gt;undefined&lt;/code&gt; in the place of actual data.  We will fill that in next.&lt;/p&gt;

&lt;h2 id=&quot;generating-a-bytestring&quot;&gt;Generating a &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt;&lt;/h2&gt;

&lt;p&gt;Now we know what format our data should be in, next we need to find out how to create a &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt;.  We’ll go to the module documentation like we did before: &lt;a href=&quot;https://hackage.haskell.org/package/bytestring-0.10.8.2/docs/Data-ByteString.html&quot;&gt;Data.ByteString&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the description of &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A space-efficient representation of a Word8 vector, supporting many efficient operations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Word8&lt;/code&gt; is going to be relevant for us, as this is the Haskell type for one byte.  If we wanted to represent our purple pixel from earlier (&lt;code class=&quot;highlighter-rouge&quot;&gt;rgba(128, 0, 128, 0.25)&lt;/code&gt;) as a list of &lt;code class=&quot;highlighter-rouge&quot;&gt;Word8&lt;/code&gt;, it would look like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;purple :: [Word8]
purple = [128, 0, 128, 64]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A fully opaque red pixel would look like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;red :: [Word8]
red = [255, 0, 0, 255]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We just need 10,000 of these in a &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt; and we should have a working image.  There is a function in the docs which will work for this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pack :: [Word8] -&amp;gt; ByteString
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Our single pixel has 4 bytes in a list, so we’ll need 40,000 bytes in a list to generate the &lt;code class=&quot;highlighter-rouge&quot;&gt;ByteString&lt;/code&gt; for a 100x100 image.  Let’s first try to make an image of just one color.  There is a function that will allow us to turn our pixels above into an infinite list of pixels:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;cycle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;-- cycle ties a finite list into a circular one, or equivalently, the infinite repetition of the original list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Laziness in Haskell makes working with infinite lists possible, since the elements of the list are not actually created until asked for.  We use the &lt;code class=&quot;highlighter-rouge&quot;&gt;take&lt;/code&gt; function to take some values from a list.&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;take&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cycle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;purple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;-- [128,0,128,64,128,0,128,64,128,0,128,64]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Alright, we are ready to update our code to draw a purple image.  First, add the &lt;code class=&quot;highlighter-rouge&quot;&gt;bytestring&lt;/code&gt; package to &lt;code class=&quot;highlighter-rouge&quot;&gt;gloss-bitmaps.cabal&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;library
  hs-source-dirs:      src
  exposed-modules:     Lib
  build-depends:       base &amp;gt;= 4.7 &amp;amp;&amp;amp; &amp;lt; 5
                     , gloss&lt;b&gt;
                     , bytestring&lt;/b&gt;
  default-language:    Haskell2010
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Add the bitmap data to our library source file:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;module Lib
    ( someFunc
    ) where

import Graphics.Gloss&lt;b&gt;
import Data.Word
import Data.ByteString (ByteString, pack)

purple :: [Word8]
purple = [128, 0, 128, 64]

bitmapData :: ByteString
bitmapData = pack $ take 40000 (cycle purple)&lt;/b&gt;

ourPicture :: Picture
ourPicture = bitmapOfByteString 100 100 (BitmapFormat TopToBottom PxRGBA) bitmapData True

someFunc :: IO ()
someFunc = display (InWindow &quot;Nice Window&quot; (200, 200) (10, 10)) white ourPicture
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Rebuild and run:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;stack build
stack exec gloss-bitmaps-exe
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017/purple_square.png&quot; alt=&quot;purple_square&quot; /&gt;&lt;/p&gt;

&lt;p&gt;At this point you have enough info to start playing around with pixel images.  Try writing code to generate some different types of pixels.&lt;/p&gt;

&lt;p&gt;In a future post, we will use &lt;code class=&quot;highlighter-rouge&quot;&gt;IO&lt;/code&gt; in Haskell to produce randomly generated pixels.&lt;/p&gt;

&lt;p&gt;The example code can be found on &lt;a href=&quot;https://github.com/johnmendonca/gloss-bitmaps&quot;&gt;GitHub&lt;/a&gt;&lt;/p&gt;</content><author><name>John Mendonça</name></author><category term="haskell" /><summary type="html">Let’s use the library gloss in Haskell to easily display images. We’ll explore the types used by gloss and create a bitmap using ByteString.</summary></entry><entry><title type="html">Formatted Date Strings in Linux</title><link href="https://mendo.zone/cmd/formatted-date-in-linux/" rel="alternate" type="text/html" title="Formatted Date Strings in Linux" /><published>2017-12-12T10:37:30-07:00</published><updated>2017-12-12T10:37:30-07:00</updated><id>https://mendo.zone/cmd/formatted-date-in-linux</id><content type="html" xml:base="https://mendo.zone/cmd/formatted-date-in-linux/">&lt;p&gt;You can easily print the current time as a formatted string using the &lt;code class=&quot;highlighter-rouge&quot;&gt;date&lt;/code&gt; command in linux:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;date &quot;+%Y-%m-%d %H:%M:%S %z&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;!-- --&gt;

&lt;p&gt;The result of this command looks like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2017-12-12 10:37:30 -0700
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The other format place holders are described in the &lt;code class=&quot;highlighter-rouge&quot;&gt;date&lt;/code&gt; manual page:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;man date
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>John Mendonça</name></author><category term="linux" /><summary type="html">You can easily print the current time as a formatted string using the date command in linux: date &quot;+%Y-%m-%d %H:%M:%S %z&quot;</summary></entry><entry><title type="html">Installing WordPress on Linux Mint for Development</title><link href="https://mendo.zone/web/installing-wordpress-on-linux-mint/" rel="alternate" type="text/html" title="Installing WordPress on Linux Mint for Development" /><published>2017-07-20T00:22:22-06:00</published><updated>2017-07-20T00:22:22-06:00</updated><id>https://mendo.zone/web/installing-wordpress-on-linux-mint</id><content type="html" xml:base="https://mendo.zone/web/installing-wordpress-on-linux-mint/">&lt;p&gt;&lt;em&gt;This tutorial uses Linux Mint 18. &lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For development and testing, you’ll often want to run WordPress on a local machine.  In Linux Mint we can get up and running quickly using a few packages and settings changes.&lt;!-- --&gt;  It should be a similar process for Ubuntu or Debian.&lt;/p&gt;

&lt;p&gt;Most of these commands need to be run as root or using &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo&lt;/code&gt;.  Try &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo -i&lt;/code&gt; if you want to enter many commands as root.&lt;/p&gt;

&lt;h2&gt;Apache Web Server&lt;/h2&gt;

&lt;p&gt;Apache handles incoming connections, and runs the WordPress PHP code. Install by running:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;apt-get install apache2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This should start the apache service when completed.  Run &lt;code class=&quot;highlighter-rouge&quot;&gt;ps ax&lt;/code&gt;, and look for lines like this:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;4088 ?        S      0:00 /usr/sbin/apache2 -k start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This shows you that the web server is running.  It will also start again when your system reboots.  When it is not running you can start it using:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;service apache2 start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also &lt;code class=&quot;highlighter-rouge&quot;&gt;stop&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;restart&lt;/code&gt; the service with this command.&lt;/p&gt;

&lt;h3&gt;Adding Modules&lt;/h3&gt;

&lt;p&gt;We are going to add two Apache modules that will help us for local WordPress development.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;a2enmod rewrite userdir
service apache2 restart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The Rewrite module is a requirement for WordPress to define custom URL patterns.&lt;/p&gt;

&lt;p&gt;The Userdir module allows regular users to host files in their home directories.  By default, Apache will only serve files from &lt;code class=&quot;highlighter-rouge&quot;&gt;/var/www/html&lt;/code&gt;, which requires root permissions to modify.&lt;/p&gt;

&lt;p&gt;With the &lt;code class=&quot;highlighter-rouge&quot;&gt;userdir&lt;/code&gt; module active, files stored in &lt;code class=&quot;highlighter-rouge&quot;&gt;/home/username/public_html&lt;/code&gt; will be served at &lt;code class=&quot;highlighter-rouge&quot;&gt;http://localhost/~username&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Create an HTML file in your &lt;code class=&quot;highlighter-rouge&quot;&gt;public_html&lt;/code&gt; folder and confirm that it is being served correctly.&lt;/p&gt;

&lt;h2&gt;PHP&lt;/h2&gt;

&lt;p&gt;Install PHP 7, the Apache interface, and a few modules that we will need:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-cli php7.0-cgi php7.0-gd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Apache will not run PHP code in a userdir by default, so we need to enable this manually.  Edit the &lt;code class=&quot;highlighter-rouge&quot;&gt;php7.0.conf&lt;/code&gt; file here:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;vim /etc/apache2/mods-available/php7.0.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There is a section at the end we will comment out by adding &lt;code class=&quot;highlighter-rouge&quot;&gt;#&lt;/code&gt; to the beginnings of the lines.  It should look like this in the end:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# To re-enable PHP in user directories comment the following lines
# (from &amp;lt;IfModule ...&amp;gt; to &amp;lt;/IfModule&amp;gt;.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#&amp;lt;IfModule mod_userdir.c&amp;gt;
#    &amp;lt;Directory /home/*/public_html&amp;gt;
#        php_admin_flag engine Off
#    &amp;lt;/Directory&amp;gt;
#&amp;lt;/IfModule&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Restart Apache to reload the config files:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;service apache2 restart&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we want to confirm that PHP files are actually being run from our userdir.&lt;/p&gt;

&lt;p&gt;Create this file:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;vim ~/public_html/info.php&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Put this in the file:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;?php
phpinfo();
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Save the file and then vist &lt;code class=&quot;highlighter-rouge&quot;&gt;http://localhost/~yourname/info.php&lt;/code&gt;.  You should see a large table of infomation generated by PHP.  If the page is blank or showing an error, then the installation/configuration is not correct.&lt;/p&gt;

&lt;h2&gt;MySQL&lt;/h2&gt;

&lt;p&gt;The last major piece is the MySQL database, where WordPress will store most of its data.  First install MySQL on your system:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;apt-get install mysql-client mysql-server&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;During the installation process, a screen will ask you to supply a password for the root MySQL user.  By default the password is blank, and it is recommended to add a password.&lt;/p&gt;

&lt;p&gt;You can improve the security of the installation by running this:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;mysql_secure_installation&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will ask you a series of questions to optionally enable security features.  You probably don’t need to use them all, but I’d recommend a few things:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Remove anonymous users&lt;/li&gt;
  &lt;li&gt;Disallow root login remotely&lt;/li&gt;
  &lt;li&gt;Remove test database&lt;/li&gt;
  &lt;li&gt;Reload privilege tables&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This tutorial is about setting up a local development environment, not a secure production environment.  The advice above will improve the security of a default installation, but would not be sufficient for production.&lt;/p&gt;

&lt;h3 id=&quot;creating-a-mysql-user-and-database&quot;&gt;Creating a MySQL user and database&lt;/h3&gt;

&lt;p&gt;We do not want WordPress to have root access to our entire database server.  We will create a MySQL user and database specifically for WordPress.&lt;/p&gt;

&lt;p&gt;Login to the MySQL console as root (this command must be ran as root or with &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo&lt;/code&gt;):&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;mysql -u root -p&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will ask you for the password you created when installing MySQL and will open a MySQL terminal with total access to the database server.&lt;/p&gt;

&lt;p&gt;To create the database and user, enter the following commands using your own values (uppercase keywords are conventional but not required):&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;CREATE DATABASE 'wordpress';
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We are now ready to install WordPress itself.&lt;/p&gt;

&lt;h2 id=&quot;installing-wordpress&quot;&gt;Installing WordPress&lt;/h2&gt;

&lt;p&gt;Go to the &lt;a href=&quot;https://www.wordpress.org/download/&quot;&gt;WordPress website&lt;/a&gt; to download the source code.  We will extract these files in our userdir:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd ~/public_html
# for zip
unzip ~/Downloads/wordpress-4.8.1.zip
# for tar.gz
tar xzf ~/Downloads/wordpress-4.8.1.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now at &lt;code class=&quot;highlighter-rouge&quot;&gt;http://localhost/~username/wordpress/&lt;/code&gt; you should see a setup page created by WordPress.  It is possible for WordPress to do the final setup here, but it would require changing the permissions of the &lt;code class=&quot;highlighter-rouge&quot;&gt;wordpress/&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;Instead we will create the file manually:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd ~/public_html/wordpress/
cp wp-config-sample.php wp-config.php
vim wp-config.php
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Edit the new &lt;code class=&quot;highlighter-rouge&quot;&gt;wp-config.php&lt;/code&gt; file and update the following values to match the database info:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wpuser');

/** MySQL database password */
define('DB_PASSWORD', 'wppassword');

/** MySQL hostname */
define('DB_HOST', 'localhost');
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Go back to  &lt;code class=&quot;highlighter-rouge&quot;&gt;http://localhost/~username/wordpress/&lt;/code&gt; and you will see a new form, asking for new user information.  This will setup the admin user of your new site.  Fill in the info and your WordPress installation is complete!&lt;/p&gt;</content><author><name>John Mendonça</name></author><category term="linux" /><category term="wordpress" /><category term="apache" /><category term="mysql" /><summary type="html">This tutorial uses Linux Mint 18. For development and testing, you’ll often want to run WordPress on a local machine. In Linux Mint we can get up and running quickly using a few packages and settings changes.</summary></entry><entry><title type="html">A Static Site Folder Structure for Github Pages</title><link href="https://mendo.zone/web/github-pages-folder-structure/" rel="alternate" type="text/html" title="A Static Site Folder Structure for Github Pages" /><published>2015-03-12T14:47:20-06:00</published><updated>2015-03-12T14:47:20-06:00</updated><id>https://mendo.zone/web/github-pages-folder-structure</id><content type="html" xml:base="https://mendo.zone/web/github-pages-folder-structure/">&lt;p&gt;GitHub Pages is a GitHub service that will host your static website files, if you push them to a specific git repo or branch. This is one of the easiest ways for git users to host static HTML, CSS, and JS files.&lt;/p&gt;

&lt;p&gt;This makes a perfect pair with a static site generator. In this article I outline a method to keep your entire static site project in one git repository.&lt;!-- --&gt;&lt;/p&gt;

&lt;h2 id=&quot;how-github-pages-works&quot;&gt;How Github Pages Works&lt;/h2&gt;

&lt;p&gt;Github Pages has two types of repositories. A User/Organization Pages repository must be named &lt;code class=&quot;highlighter-rouge&quot;&gt;username.github.io&lt;/code&gt;. This project will publish the contents of branch &lt;code class=&quot;highlighter-rouge&quot;&gt;master&lt;/code&gt; as a static site. Create a git repository in the output directory and &lt;code class=&quot;highlighter-rouge&quot;&gt;git push origin master&lt;/code&gt; to deploy your site.&lt;/p&gt;

&lt;p&gt;A Project Pages repository is more flexible. In this type, the static site is published from the branch &lt;code class=&quot;highlighter-rouge&quot;&gt;gh-pages&lt;/code&gt;. This leaves &lt;code class=&quot;highlighter-rouge&quot;&gt;master&lt;/code&gt; free for the code of a software project. In our case we will store the source files of our website in &lt;code class=&quot;highlighter-rouge&quot;&gt;master&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Using the method below, we can keep the source and output in separate branches, while maintaining the default folder structure of our project.&lt;/p&gt;

&lt;h2 id=&quot;setting-up-the-project&quot;&gt;Setting Up The Project&lt;/h2&gt;

&lt;p&gt;Every static site generator will use a specific folder structure, with the generated output usually in one subdirectory. We want our branch &lt;code class=&quot;highlighter-rouge&quot;&gt;gh-pages&lt;/code&gt; to be at the root of the output subdirectory. Our &lt;code class=&quot;highlighter-rouge&quot;&gt;master&lt;/code&gt; branch will be one level up, at the root of the entire project. We can use &lt;code class=&quot;highlighter-rouge&quot;&gt;.gitignore&lt;/code&gt; to nest one instance of the repository within the other.&lt;/p&gt;

&lt;p&gt;Here is a step-by-step process to set this up:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Create a local project using your site generator of choice&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;git init&lt;/code&gt; a repository inside the project and push to a remote repository on GitHub&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Create or edit your &lt;code class=&quot;highlighter-rouge&quot;&gt;.gitignore&lt;/code&gt; file and add the output directory of your project to the ignore list.&lt;/p&gt;

    &lt;p&gt;At this point, change and build your site. Do a &lt;code class=&quot;highlighter-rouge&quot;&gt;git status&lt;/code&gt;. You should only see changes to the source files, and not for the output folder.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Go ahead and delete that output folder&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Now clone your project from Github, into the place where the output folder just was. Rename it to match the original folder name. You can do this all at once using: &lt;code class=&quot;highlighter-rouge&quot;&gt;git clone &amp;lt;git-url&amp;gt; &amp;lt;folder-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

    &lt;p&gt;Now we have have two copies of the repo, one nested inside the other. The outer source repo is blissfully ignorant of the inner one thanks to &lt;code class=&quot;highlighter-rouge&quot;&gt;.gitignore&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Move into the inner repository. It should contain a copy of the project source which we now want to remove.&lt;/li&gt;
  &lt;li&gt;Create the new branch: &lt;code class=&quot;highlighter-rouge&quot;&gt;git checkout -b gh-pages&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Make sure the current branch is &lt;code class=&quot;highlighter-rouge&quot;&gt;gh-pages&lt;/code&gt;. Then use &lt;code class=&quot;highlighter-rouge&quot;&gt;git rm&lt;/code&gt; to remove the entire contents of the folder.&lt;/li&gt;
  &lt;li&gt;Build your site. The inner gh-pages repository should now contain the build output from your generator (the static website).&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;git add&lt;/code&gt; the files, &lt;code class=&quot;highlighter-rouge&quot;&gt;git commit&lt;/code&gt;, and finally &lt;code class=&quot;highlighter-rouge&quot;&gt;git push origin gh-pages&lt;/code&gt;.&lt;/p&gt;

    &lt;p&gt;Your site should now be published on Github Pages.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;For the outer repository, you will commit and push to &lt;code class=&quot;highlighter-rouge&quot;&gt;master&lt;/code&gt; any changes to the source files.&lt;/li&gt;
  &lt;li&gt;Commit and push to &lt;code class=&quot;highlighter-rouge&quot;&gt;gh-pages&lt;/code&gt; from within the output subdirectory.&lt;/li&gt;
&lt;/ol&gt;</content><author><name>John Mendonça</name></author><category term="github-pages" /><category term="static-site" /><summary type="html">GitHub Pages is a GitHub service that will host your static website files, if you push them to a specific git repo or branch. This is one of the easiest ways for git users to host static HTML, CSS, and JS files. This makes a perfect pair with a static site generator. In this article I outline a method to keep your entire static site project in one git repository.</summary></entry></feed>