6 Erlang Libraries

6.1 What's in the OTP libraries?

The full library descriptions are included with the open-source distribution and also on line. The highlights are:

6.1.1 O&M Support

SASL, EVA, INETS and SNMP provide Operations- and maintenance-related functionality: release handling, alarm and event handling, administration via web browser and SNMP.

6.1.2 CORBA

ORBER, CosEvent, CosTransactions and IC contain support for everything CORBA related.

6.1.3 Database

Mnesia and Mnemosyne provide a real-time distributed database which can be both in-RAM and on-disk. There is also a standard ODBC client driver.

6.1.4 ASN.1

There is an ASN.1 compiler which produces Erlang code.

6.1.5 Standard Library

A rich collection of modules provides everything from string, list and regular expression manipulation to random number generation and calendar lookups.

6.1.6 Structural Components

gen_server, gen_fsm, and supervision trees provide standard ways of implementing client/server subsystems, state machines and supervised fault-tolerant systems.

6.1.7 GUI and Graphics

gs and webtool provide ways to build a gui.

Among other things, there is also a web server and a GUI interface.

6.2 Is there a collection of data structures, e.g. balanced trees?

Linked lists are a fundamental part of Erlang, as are tuples. The other standard data structures are:

Standard data structures
Module Description
sets sets, i.e. a collection of unique elements.
gb_sets sets, but based on a general balanced data structure
gb_tree a general balanced tree
dict maps, also called associative arrays
ets hash tables and ordered sets (trees)
dets on-disk hash tables

The contributions area at the erlang.org site includes modules for double-ended queues and balanced trees.

ordset and orddict are not really suitable for large amounts of data: they are no better that lists for many common operations, e.g. inserting an element is O(n) for both. dict and sets are usually preferred.

In practice, Erlang programs use lists (either natively or via dict) for data structures involving up to a few hundred elements and use ETS (the Erlang Term Store) or mnesia for anything larger. ETS uses hashing to allow near constant-time access to almost arbitrarily large amounts of data.

For a collection of data consisting of a few (tens or hundreds) items, lists often outperform both ETS and trees. For large numbers of small items, ETS tends to work best. For larger items, balanced trees can outperform ETS because they avoid copying the data.

6.3 Is there a serial port driver for Erlang?

Johan Bevemyr wrote one which works for unix machines. The code is freely available at the contributions area as serial-1.0.

There have been discussions on the mailing list about writing a more general driver which also works on windows machines. Nothing much has come of this (lack of interest?).

6.4 Is there a toolkit for building GUIs?

There are several. The reliable-but-ugly option is gs, which is described here. gs works on both windows and unix (X Window System).

Many people prefer to use etk which is a fairly direct binding to the well-known TK toolkit.

Other graphics-related items on sourceforge are gtkNode (a C node which gives access to a large subset of GTK2) and gd1_drv (a driver which dynamically creates JPEG and PNG images). There are a few projects involving experimental graphics interfaces, including a binding to gtk (Ed: can someone send me some more information about this!), an OpenGL modeller and some interesting work to directly access the X protocol.

Finally, many projects which use Erlang recognise that very fine tools are available for creating GUIs using Java, so they use Java for the GUI portion of a system. Jinterface is one way to interface Erlang to Java.

6.5 I've written a library to handle XYZ. How do I get it into the standard Erlang distribution?

This takes more work and patience than most people have. Kent Boortz described many of the hurdles on the mailing list.

There are other ways to spread your code, including distributing it from your own website or adding it to the jungerl.