Universe Library for OCaml
September 27, 2015
1 What is the Universe Library for OCaml?
Racket has a wonderful
for writing interactive games.
For quick introduction, see a draft but wonderfully written textbook
How to Design Worlds
(for non-communicating games).
For thorough introduction, see the 2nd edition of
How to Design Programs.
The Universe Library for OCaml provides similar interface in
OCaml, so that one can enjoy writing interactive games in OCaml.
We are developing the Universe Library using the following environments:
3 Setting up
You need to have X11, gtk2, gnomecanvas, lablgtk2, and
We do as follows:
- Install gtk2, gnomecanvas, and lablgtk.
sudo port install cairo +x11
sudo port install gtk2 +x11
sudo port install libgnomecanvas
sudo port install pkgconfig
opam install ocamlfind
opam install conf-gnomecanvas
opam install cairo2
opam install lablgtk
- Install OCamlMakefile.
opam install ocaml-makefile
opam pin add universe https://github.com/kenichi-asai/Universe.git
Or you can do it manually:
Download the universe library from the github
- The library has the following directory structure:
Universe/library/ : the Universe library
Universe/sample/ball-game1/ : sample non-communicating game
Universe/sample/ball-game2/ : sample communicating game
Create a link to OCamlMakefile in the Universe directory.
If you installed OCamlMakefile via OPAM, type somethig like:
ln -s ~/.opam/4.01.0/lib/ocaml-makefile/OCamlMakefile .
- Under the Universe/library directory, compile:
6 Sample games
Non-communicating ball game (source:
Click balls to make them all smallest.
- Run: ./game
- Communicating ball game (source:
Click the others' balls.
When your balls all become smallest, you lose.
- Launch a server: ./server
- It will output a port number.
- Launch clients as many as you want:
./client [hostname] port-number
7 Create your own games
- communicating games
Create a directory under sample.
- Copy Makefiles from ball-game2.
cp ../ball-game1/Makefile .
cp ../ball-game1/Makefile-client .
cp ../ball-game1/Makefile-server .
- Edit Makefile-client and Makefile-server.
- Develop your game!
- To compile: make
- To run, first launch a server.
It will output a port number.
You can then launch as many clients as you want.
./client [hostname] port-number
From the same machine as the server is running, you can omit the host
8 Create a toplevel with the Universe Library
If you installed the library via OPAM:
ocamlfind ocamlmktop -package universe,findlib -linkpkg -o universe.top
and you will obtain universe.top.
To launch the toplevel, simply type:
and then in the toplevel:
#require "universe" ;;
ocamlfind ocamlmktop -package lablgtk2.gnomecanvas,unix -linkpkg -I ../../library socket.cma color.cma image.cma world.cma -o universe.top
To launch the toplevel, you need to specify the library path:
./universe.top -I ../../library
9 Known issues
Comments in ml files are in Japanese.
- The @en and @ja tags in mli files are not
working as intended.
A feature request
has been placed.
Uehara, C., and K. Asai
``Cross validation of the universe teachpack of Racket in OCaml,''
The 4th International Workshop on Trends in Functional
Programming in Education (TFPIE 2015), 14 pages (June 2015).
- 上原 千裕, 浅井 健一
「LablGtk2 を用いた universe teachpack の実装」
日本ソフトウェア科学会第 31 回大会 (2014 年度) 講演論文集,
This document was translated from LATEX by