posts by Jesse Hallett

How to install Haskell “Batteries Included” Platform on Ubuntu Jaunty

Just for kicks I thought I would take another shot at some Haskell programming. To get all of the common libraries and the automated package installer, cabal, I set up the Haskell Platform. Here is how I did it.

Ubuntu Jaunty includes a package for the Haskell compiler, ghc, at version 6.8. The Haskell Platform installer will roll its eyes at you if you try to proceed with this version of ghc. So the first step is to install ghc 6.10.

Paste these lines into /etc/apt/sources.list.d/haskell.list:

deb jaunty main
deb-src jaunty main

To get the key to verify packages from that PPA, run this optional command:

sudo apt-key adv --keyserver --recv-keys E51D9310

Then update your package list and install Haskell:

sudo apt-get update
sudo apt-get install ghc6 ghc6-prof ghc6-doc haddock

The Haskell Platform website does not list a package for Ubuntu yet. So download the source installer.

Database Queries the CouchDB Way

CouchDB is a document-oriented database. It has no rows or tables. Instead CouchDB is a collection of JSON documents. It uses a map-reduce pattern to index data. Queries in CouchDB pull data from what are essentially stored procedures called views. A view is made up of a map function and optionally a reduce function. Ninety percent of the time all you need is the map function, so I will focus on map-only views here.

A map function is a JavaScript function that takes a single document as an argument and emits any number of key/value pairs. Both the key and the value can be any JSON value you choose. The map function is run on every document in the database individually and the emitted key/value pairs are used to construct an index of your data.

A Simple Example

Imagine you have a database with user records and you want a view of those records using the last name of each user as keys.

function(doc) {
    if (doc.last_name) {
        emit(doc.last_name, doc);

The above map function will produce and index something like the one below. Because doc is used as a value for each entry the entire content of each JSON document will be accessible as the indexed values.

  { key: "Clarke", value: { last_name: "Clarke", ... } },
  { key: "Kelly",  value: { last_name: "Kelly",  ... } },
  { key: "Smith",  value: { last_name: "Smith",  ... } },

Notice that the map function checks each document for a last_name attribute before emitting a key/value pair. There may be documents in the database that are not user records. By performing that check the view excludes any non-user-record documents from the resulting index.

How to use RSpec to describe a Sinatra application

This information was written a long time ago and has become pretty outdated.

Sinatra is a fun little web application microframework. Recently I started working on an application using Sinatra - and since I am working on good programming habits, before I dove into any coding I sat down to work out how to write specs for a Sinatra application.

Sinatra comes bundled with support for test/spec: a spec framework that builds on top of Rail’s own Test::Unit to provide support for writing specs. Which is a really neat idea. But I have been using RSpec for my other work, and I wanted to continue doing so.

It turns out that RSpec takes a little bit of manual work to get going with Sinatra. I read a helpful article on that pointed me in the right direction. The article advised me to add these lines to my spec files:

require File.expand_path(File.dirname(__FILE__) + '/your_application')
require 'spec'
require 'spec/interop/test'
require 'sinatra/test/unit'

The first line loads your application; the second line loads RSpec; the third loads an RSpec-Test::Unit compatibility layer; and the fourth loads Sinatra’s test helpers, which are written for Test::Unit.

International Phonetic Alphabet

In last week’s post I provided phonetic transcriptions of some example words using the International Phonetic Alphabet, or IPA for short. I thought it would be helpful to follow that up with some information about what the IPA is, and how to read it. And as a bonus, after learning about IPA transcription you will be able to better read pronunciation guides on Wikipedia.

You have probably seen many phonetic transcriptions before - especially as pronunciation guides in dictionaries. In dictionaries it is common to see a transcription convention that uses English spelling conventions to represent sounds. For example, the word “elucidate” might be transcribed as (ee-LOO-suh-date). That system is handy because it is immediately familiar to anyone who has experience reading stuff in English. But it has drawbacks too. There are a few main problems that are especially important for linguists; there are lots of linguists all over the world who are used to languages with entirely different spelling conventions. For example, the sound in English that is represented as “y” - the consonant, not the vowel - is written in Icelandic as “j”. There are also a lot of languages with sounds that just don’t exist in English. Linguists need to be able to transcribe those sounds; but since they don’t exist in English there is no spelling convention to represent them. In fact there is no one language with enough spelling conventions to represent every sound in every language in the world. And finally, English spelling is ambiguous, as is the spelling of almost any language. That is already demonstrated by the need to add a note to distinguish “y” the consonant from “y” the vowel or any of the other vowel sounds represented by “y”.

Anatomy of a Syllable

The syllable is a constant feature in every spoken language in the world. Each language has its own rules about what kinds of syllables are allowed, and what kinds aren’t - but the general structure is the same everywhere.

A syllable has as many as three parts: onset, nucleus, and coda. The onset and the coda are consonants, or consonant clusters, that appear at the beginning and the end of the syllable respectively. The nucleus forms the the core of the syllable; it is most often a vowel, or a combination of vowels - but there are many exceptions to that. If you examine enough languages you can find almost every kind phone used as a syllable nucleus. In the word “far”, [f] is the syllable onset, [a] is the nucleus, and [r] the coda. If a coda is present in a syllable, the nucleus and the coda form a single unit called a rhyme; otherwise the nucleus makes up the rhyme by itself. Looking at “far” again, [ar] forms the rhyme. A syllable does not necessarily have to have an onset or a coda - depending on the language - but a nucleus is always present.

Even in English, syllable nuclei are not restricted to vowels. For example, in the monosyllabic word, “hmm”, the syllable nucleus is [ṃ], which is a consonant but is more specifically a nasal. Another nasal, [n], can be seen as a syllable nucleus in the word “isn’t”, which is transcribed into the International Phonetic Alphabet (IPA) as [ɪzzṇt]. In this case there are two syllables, and [ṇ] forms the nucleus of the second syllable.


When someone says to you, “here” or “now”, you probably know what he means. “Here” might the room that you are both sitting in. “Now” would be the span of time you spent sitting together. But if either word were uttered under different circumstances, it could mean something very different. For example, if I called you from the Andes and I used the word, “here”, it would mean a mountainside somewhere - possibly thousands of miles away from the aforementioned room. The same word can mean both the room and the mountainside because of deixis.

Deixis is a form of exophora, which is an utterance that is given meaning by the context it is uttered in. Specifically, deixis represents the speech event itself: deictic expressions reference the speaker, the speaker’s utterances, the speaker’s location, and the time at which the speech event occurs. There are different types of deictic expressions that refer to each particular aspect.

Personal pronouns, such as “I”, “you”, “he”, and “she”, are deictic expressions. “I” refers simply to the speaker. The other pronouns are defined by the relation the referenced person has to the speaker in the discourse. As the role of speaker switches from person to person, the context represented by deixis in understood by participants of the discourse to change too.