[Haskell-cafe] Tetris

Andrew Coppin andrewcoppin at btinternet.com
Tue Nov 20 14:27:48 EST 2007


Don Stewart wrote:
> andrewcoppin:
>   
>> If you were going to implement Tetris in Haskell, how would you do it?
>>
>> (For that matter, has anybody already *done* it? It would probably make 
>> a nice example program...)
>>     
>
> http://haskell.org/haskellwiki/Applications_and_libraries/Games
>
>     ASCII tetris
>     http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/Hetris/
>
> OpenGL or Gtk2Hs seem the best options.
>   

OK, well I'll have a go at seeing if I can put something together with 
Gtk2hs.

(Nitpick: Don't you need Gtk2hs in order to *use* OpenGL? I mean, you 
have to open a window to render into somehow, and that's outside the 
OpenGL standard...)

>> 2. How do you implement a program that is fundamentally about state 
>> mutation in a programming language which abhors state mutation?
>>     
>
> Its not clear games are fundamentally about mutation, anymore than, say,
> window managers are. State we do with monads.
>   

Hmm. On reflection, Tetris is probably a poor example of this. It has a 
fairly small, simple state that you can easily manipulate purely 
functionally. But if you imagine, say, an FPS game, where you have 
(possibly multiple) players running around, NPCs running after them, 
possibly a nontrivial physics engine, possibly a nontrivial AI system, 
possibly nontrivial scripted sequences happening... how do you *do* all 
that in Haskell?

> Check the thesis on Frag for a pure approach, or just use StateT IO.
>   

Indeed, Frag is interesting because it conclusively demonstrates that 
this can be done in Haskell (by doing it!) However, all the material 
I've read about it is unfortunately utterly incomprehensible. I still 
have no idea how it is possible to build such a highly interactive 
system in a language which strongly discourages interactivity...



More information about the Haskell-Cafe mailing list