43

I'm quite new to that functional programming paradigm, but so far I like it. Since I'm into game development, I want to try it out in writing some games in purely functional programming style. I don't mind the language - be it Erlang, Haskell, Lisp, or even Ruby (I found out it supports functional programming traits).

Well, it is obvious that to learn functional programming (in fact, anything) the best advice would be just to learn functional language and program a lot in it. But what I'm looking for are some resources on using functional programming in games and game engines (2D or 3D).

So, do you know of any functional programming articles/books/blogs/whatever about using it in actual games, or designing simple game engines with functional programming languages, and all the interaction between the game and game engine in this functional environment?

Please, don't suggest something like "just start programming simple stuff in functional and gradually it will come to you". As I said earlier, it is obvious, but what I'm asking here are some resources on the topic, if there any. Thanks!

Thomas Owens
  • 107,741
  • 94
  • 299
  • 427
Mikka
  • 2,073
  • 2
  • 16
  • 11

9 Answers9

23

Well, you could do worse than studying the code of some of these haskell games.

Some of these use FRP (functional reactive programming), which some people are working on as a pure, high-level technique for games and other things. But most are a typical haskellish mixture of effectful and pure functional code.

Bloggers with relevant content include James Hague.

Note FunGEn at the first link - though not actively maintained it is a 2D game engine with working examples.

There's also the Clean language with it's game library and nice screenshots.

Simon Michael
  • 2,250
  • 1
  • 18
  • 20
7

Well I am mostly a Haskell programmer so I can only suggest to try Haskell libraries such as Gtk2hs. Its mostly for 2D applications and for user interfaces but its good to get you started :) An even easier library is HGL but its slightly bugged and outdated. If you want to try out messier (but cooler!) stuff then go for Haskell's OpenGL library which can be found here. I never tried working with Haskell and OpenGL but if you check out the answer submitted by Simon Michael there are example games in Hackage's Game Section which use OpenGL.

Sorry about not linking all the libraries but I'm a new user and I'm not allowed more than one hyperlink. If you google them they should come up easily though.

7

If you are interested in the networked side of games, Joel Reymont has written about his experiences coding up an online Poker server. I think he did at least three different implementations (Lisp, Erlang, Haskell). Unfortunately, his material is scattered across the Internet. Here are two pointers you might find useful:

EDIT:

Here are some follow-up pointers and links from the above documents that have changed.

EDIT II:

Joel has apparently sold his poker code since, hence it is no longer available as open source.

ThomasH
  • 19,270
  • 9
  • 53
  • 57
  • that last link seems to have confused the hell out of the parser. hopefully i didn't screw it up that bad by not referencing the web archives. – nlucaroni Jul 31 '09 at 17:57
  • 1
    Maybe you could have just used tinyurl or something like that :) – Mikka Aug 01 '09 at 11:37
4

A little dated, but this is the first in a series of posts on how to use F# with the XNA game development framework. You might also find the blog F# for Game Development has some useful material.

mattnewport
  • 12,751
  • 2
  • 30
  • 38
3

Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It is licensed under the GPL. The design and implementation of Frag is described in Mun's undergraduate thesis, Functional Programming and 3D Games.

hiena
  • 895
  • 1
  • 8
  • 9
2

Try this Casting SPELs

Gutzofter
  • 1,965
  • 22
  • 26
1

Wings3D is the Erlang package that is used in to draw wireframe shapes. I think it is used in games, but that's not my bag...

Gordon Guthrie
  • 6,122
  • 2
  • 25
  • 50
  • 1
    The github.com/dgud/esdl/tree/master library is used in wings3d, but the author recommends using wxerlang to get to opengl. – Christian Jul 30 '09 at 21:54
1

Well, I'm not sure how much this helps, and you've probably heard of it already, but seems like an obvious start: here's an article on Jak and Daxter.

varzan
  • 589
  • 3
  • 18
  • 1
    Even though GOAL was a Lisp, I don't think it was very functional. All the code samples look imperative and somewhere I remember reading about how they managed memory manually because the GOAL garbage collector was too slow. (However, the article does summarise many other advantages of Lisp--macros, runtime evaluation, etc.) – Nathan Shively-Sanders Jul 30 '09 at 20:44
  • Another game that used Lisp was "Abuse", which is now public domain. Though, again, probably not the most functional use of Lisp. – Ken Jul 30 '09 at 21:16
  • 1
    Lisp is not that much of a pure 'functional programming language' anyway. Usually it is multi-paradigm and supports the inclusion of many other paradigms (logic, rules, relational, constraints, agents, ...). So any real Lisp program will happily mix imperative, functional, object-oriented and other programming styles. – Rainer Joswig Jul 30 '09 at 23:14
  • I actually did read this article, long ago, so long that I've forgotten what it was all about :) – Mikka Aug 01 '09 at 12:16
1

As Nathan Sanders states above (from my own googling on "haskell games gc") there was a time when Haskell had(?) some pretty serious issues with GC... this old article (6 years old, I know), also see this question. Since Frag is around, I guess they must have fixed at least some things in the later versions of GHC.

Community
  • 1
  • 1
Engineer
  • 7,543
  • 7
  • 57
  • 96