[TYPES/announce] Book on functional programming and game development

Giuseppe Maggiore giuseppemag at gmail.com
Tue Aug 23 10:05:24 EDT 2011


I am writing here in the hope that it may be of interest to some;
functional programming is very often regarded as a difficult, academic
topic with very few fun or realistic applications. I have just
finished co-authoring a book, Friendly F#, that shows just how that
may not be true.

The book aims at teaching the F# language through a series of samples
that are fully centered on game development and simulations. Each one
of the first 5 chapters describes a problem, shows and discusses its
solution in F# and then discusses in depth the constructs used. From
this point of view the book is relatively unique, in that it
completely focuses on a problem-solution approach where everything is
explained because of how well it works in solving the problem, and not
just "because". The 5 problems are:
- a bouncing ball
- the Saturn V rocket
- an asteroid field
- a large asteroid field optimized with quad trees
- a police starship that must fight off a pirate ship attacking a
cargo freighter

In the first 5 chapters we will learn (listed chapter-by-chapter):
- basic control flow, tuples, functions
- basic data structures and information flow (records and units of measure)
- lists and sequences
- trees and discriminated unions
- computation expressions (monads) and coroutines to build State
Machines and AIs

In the last two chapters we will see how to build first a 2D and then
a 3D renderer for two of the samples we have seen. These renderers are
made in XNA, of which we show the basics in terms of the SpriteBatch,
the Model class, input management and audio.

The book is recommended for programmers who are already familiar with
(at least) an imperative programming language; a little bit of
knowledge of object-orientation may help in the latest chapters, but
it is by no means required. The book may also be read by complete
beginners to programming, but in that case the reader should expect to
have to *study* the book and not just read it; studying the materials
of the book though is not particularly unexpected, given their origin:
both authors teach Computer Science with F# and games at Ca' Foscari
University of Venice, and thanks to this we have already battle tested
many of the examples and the general approach used in the book.
Chapter 5 in particular should be of interested even for advanced
(functional) programmers, given the in-depth treatment of computation
expressions (monads) for creating small languages embedded inside F#.

We are planning on using the book extensively in the classroom next
year, and we hope that somebody else can find it of use. If anybody is
interested in using the book to try and teach a "fun fun course" (pun
intended) then by all means drop me a line at "giuseppemag AT gmail
DOT com".

The samples may be downloaded freely at:

Best regards,
Giuseppe Maggiore

More information about the Types-announce mailing list