Functional Approaches to Morphology (lab)

Grammatical Framework

Grammatical Framework (GF) is a functional tool from the Chalmers University of Technology in Göteborg. Like FM, GF is written in Haskell. But it goes a step further, provides some syntax of its own and defines itself as a programming language. It aims at describing also sentence structure, that is, syntax, using mildly context-sensitive grammars. But it has powerful morphological devices, too.

You can download GF and install it on your own computer, it is available for both Linux and Windows (see tips and tricks on GF in Windows at the end of this chapter). GF is now also available in our Linux lab at /usr/local/bin/gf. Download sample GF files with Czech paradigms here:

unzip ; rm
cd cs

GF assumes that a grammar can be multilingual. There is always some abstract syntax, which is language-universal, and concrete syntax in one or more languages. Each of them is in a separate file; to describe one language, e.g., Czech, we will thus have at least two files: (abstract) and (concrete for Czech). Morphology will always be described in the concrete part. You can either launch GF with the concrete file as an argument, or launch GF without arguments and load the concrete file with the command import


Once inside, we can use the command morpho_analyze (or short ma) to analyze a word:

ma "matce"
Mother : s Sing Loc
Mother : s Sing Dat

We can also analyze all words in a file:

read_file "bible.txt" | ma

Another command, linearize (or short l), is used to generate text from the grammar. With the -table switch, it will generate all morphological forms of a word together with morphological features that define them:

l -table Mother
s Sing Nom : matka
s Sing Gen : matky
s Sing Dat : matce
s Sing Acc : matku
s Sing Voc : matko
s Sing Loc : matce
s Sing Ins : matkou
s Plur Nom : matky
s Plur Gen : matek
s Plur Dat : matkám
s Plur Acc : matky
s Plur Voc : matky
s Plur Loc : matkách
s Plur Ins : matkami

The command compute_concrete (or short cc) is used to test individual functions (operations) defined in a module. However, we first have to import the module with the -retain option. Suppose the module is named and it contains oper isVowel : Str -> Bool:

import -retain
> cc isVowel "a"
cd ..
unzip ; rm
cd food

parse -lang=FoodEn "this Italian cheese is very expensive" | l

Notes on Getting GF Running in Windows

It can work in UTF-8 but there are issues with this encoding in Windows (including Windows 10). Make sure that the Windows console where GF will run is switched to UTF-8 right after it is launched and before you run any other commands in it. Create a shortcut to cmd.exe and tell it to start with the command chcp 65001, which will set the character encoding to UTF-8:

C:\Windows\System32\cmd.exe /k "chcp 65001"

With this UTF-8-enabled console, GF should work, even though it will occasionally issue a warning that the default encoding was changed from Latin 1 to UTF-8 (even if you invoke it with the coding switch, gf --coding=utf8). However, it seems that adding a coding flag to the concrete grammar module helps in the end:

    coding = utf8 ;

To be able to use existing GF libraries, including the Haskell module Prelude adapted to GF, we must set the environment variable GF_LIB_PATH to the folder alltenses in our copy of GF. The on-line help says it is somewhere in AppData\Roaming\cabal\gf... but the fact is, the Windows version can be just downloaded and unpacked anywhere you like it to be. So, provided that you have GF in C:\Users\Dan\Documents\Linguistics\gf (and provided your version of GF is 3.9), you will set the variable to


Setting environment variables in Windows is itself not trivial, or at least not obvious, and the exact location where it can be done differs by Windows version. In the Czech mutation of Windows 10, open the settings in the start menu, then go to Systém (System), O systému (About the system; lower left corner), Související nastavení / Informace o systému (Related settings / Information about the system; right column upper section), Upřesnit nastavení systému (Advanced system settings; last item in the left column), Proměnné prostředí... (Environment variables...; a button at the bottom of the tab). When you are here, I would recommend that you also add C:\Users\Dan\Documents\Linguistics\gf\bin to the PATH variable. You must set the variables before you launch the console window.

Haskell FM by Markus Forsberg (archive)

Functional morphology uses (is written in) functional programming languages like Haskell. In the case you do not know Haskell, here are a few tips to get you started:

Functional Morphology is a library for Haskell written by Markus Forsberg and Aarne Ranta at Chalmers University of Technology, Göteborg, Sweden. It is available for download at However, it is no longer maintained (the last update to the website was in December 2008) and it does not run off-the-shelf in current systems. The Haskell sources (*.hs) probably need a few tweaks to compile. It seems that in earlier versions of Haskell some types and functions were defined in modules that had to be explicitly imported, while now these modules are no longer available. Module List is now Data.List, Char is now Data.Char, Maybe is now Data.Maybe, IO is now System.IO, Monad is now Control.Monad. Unfortunately there is at least one module (ErrM) which does not compile for reasons other than missing common libraries (I think).

tar xzf fm_latin_v2.2_beta2.tgz

The module Data.HashTable used to be part of the base Haskell libraries but it was deprecated and disappeared from version (April 2014; the last version where it was available was, January 2013). According to the revision history of the GHC project, it was marked as deprecated on 29 June 2012, with the recommendation to use an alternative, e.g. the hashtables package, instead. That package is indeed available and can be installed using a tool called Cabal, but the modules it provides are not directly compatible with the old base library; most importantly, there is no module Data.HashTable (although there are submodules within that namespace, e.g. Data.HashTable.IO). Hence Functional Morphology has to be updated to get along without Data.HashTable before it can be run in recent versions of Haskell.