Building Yi (2008)

Yi is a text editor written in Haskell. It is similar to emacs; you can write extensions in haskell and load them into the running yi application. I think Yi is a great case study for haskell newbies, because it’s a stateful gui app, readin’ and writing and generally doing all the things that people assume haskell “can’t do”.

Yi requires recent versions of several packages, which can make it fiddly to install with. This page describes how I got yi running on my machine. I use ubuntu and the bash shell; you might need to translate if you don’t.

Prerequisites

You need developer tools such as ‘make’ and ‘darcs’ installed. Best plan is to keep following these instructions and if you get a ‘missing command’ or ‘missing library’ error, use “apt-cache search” and “apt-get install” to grab it.

We’ll put source code into ~/HaskellSource and the installed binaries into ~/Haskell. I don’t like installing experimental stuff system-wide, so this way keeps things separate.

$ mkdir ~/Haskell ~/HaskellSource

Installing ghc

Yi needs a recent version ghc, so we’ll install it from source (which takes a while)

cd ~/HaskellSource

wget http://www.haskell.org/ghc/dist/6.8.2/ghc-6.8.2-src.tar.bz2
wget http://www.haskell.org/ghc/dist/6.8.2/ghc-6.8.2-src-extralibs.tar.bz2

tar jxvf ghc-6.8.2-src.tar.bz2
tar jxvf ghc-6.8.2-src-extralibs.tar.bz2

rm *.tar.bz2

cd ghc-6.8.2

Compiling and installing ghc takes quite a while …

./configure --prefix=$HOME/Haskell && make && make install

Now, if everything worked we should have commands like ‘ghc’, ‘runghc’ and ‘ghci’:

export PATH=$HOME/Haskell/bin:$PATH
ghc --version # should say 6.8.2

Installing tools from hackage

Yi needs some additional parser libraries which are available via hackage.haskell.org. We’ll install them locally into ~/Haskell.

Let’s have some fun whilst we do this. I assume that if you’re interested in Yi then you probably like functional programming. Let’s make some functions (in bash) to help us!

# Eg. "apply ls /tmp /usr" runs "ls /tmp" then "ls /usr"
function apply ()
{
  cmd=$1
  shift
  for x in $*; do $cmd $x; done
}

# Build and install a cabal package locally
function haskell-build ()
{
  DIR=$1
  ( cd $DIR;
    runghc Setup.*hs configure --user --prefix=$HOME/Haskell
    runghc Setup.*hs build
    runghc Setup.*hs install
  )
}

Now let’s actually grab and install the required packages. Firstly “vty”, which is an ncurses-like library to manage redrawing a text console.

cd ~/HaskellSource
darcs get http://members.cox.net/stefanor/vty
cd vty
haskell-build

And next we need parser/lexer generators:

cd ~/HaskellSource
apply wget http://hackage.haskell.org/packages/archive/alex/2.2/alex-2.2.tar.gz \
           http://hackage.haskell.org/packages/archive/happy/1.17/happy-1.17.tar.gz \
           http://hackage.haskell.org/packages/archive/fingertree/0.0/fingertree-0.0.tar.gz

apply "tar zxvf" *.tar.gz
apply haskell-build alex-2.2 happy-1.17 fingertree-0.0

rm *.tar.gz

Now we’re ready to get Yi itself!

Yi itself

If you want to play it safe, you can grab one of the released versions of Yi.

cd ~/HaskellSource
wget http://hackage.haskell.org/packages/archive/yi/0.3/yi-0.3.tar.gz
tar zxvf yi-0.3.tar.gz
haskell-build yi-0.3

And you’re done!

Or, you can live life on the edge and grab the latest bleeding edge version of yi straight from its darcs repository.

cd ~/HaskellSource
darcs get http://code.haskell.org/yi/
cd yi

We need to create a ‘config.mk’ file before we run make so it knows where to install yi. You could either copy config.sample and edit it by hand. Or you could use sed thusly:

sed '/^prefix/ c\prefix = $(HOME)/Haskell' < config.sample  > config.mk

Now we can actually compile yi

make all

Configuring Yi

Yi’s equivalent of the .emacs file is ~/.yi/YiConfig.hs. You can grab a good starting point from the examples/ directory of the source tree (or ~/Haskell/share/yi-0.3/examples/ if you went for a released version)

mkdir ~/.yi
cp examples/YiConfig.hs ~/.yi

.. or ..

cp ~/Haskell/share/yi-0.3/examples/YiConfig.hs ~/.yi

Running Yi

Finally we are ready to run yi! If you’re a bleeding-edge source bunny then do:

make run-inplace

Or, if you went for a released version of yi:

~/Haskell/bin/yi

If that worked, you can move on to Hello World!.

Up to the index, or onwards to hello world example.