Good afternoon, adventure lovers!
Of course, you played the text adventure game Zork. Do you still remember these weeks when you were looking for the entrance to the dungeon, or thought about how to get past the goblins with batons. You remember how you waved a sword, you even tried various options "hit self" and "kill self". The program understood your commands - the result was predictable ... It was fun and surprising to learn the Zork text world! And you, of course, wanted to create something similar with your own hands. So maybe try? Together? In this tutorial, you will step by step create your text game in the wonderful Haskell language.
I will try to explain all the concepts used in such detail, as if telling it to those who do not know anything about Haskell - or even about programming. This may not always work out, since the manual is written in parallel with the code for learning the language. I am ready to answer all your questions if I can. Sophisticated Haskellists may find the answers, explanations, and program code somewhere clumsy or not completely true. This is nothing: the farther into the forest,
the angrier the wolves the richer the flora and fauna. We have a piece of clay - and soon it will become something decorated, a vase, for example. I cannot say in advance how many articles there will be, how they will look, and what we will come to. "To know the way and go through it is not the same thing."
Why Haskell, not F #, OCaml, Erlang, Lisp ...? Haskell of them is a dark horse. Judge for yourself. Lisp is a very ancient and very powerful multi-paradigm language. One of the best, one of the highest. He has long occupied his niche, gave the art of programming many ideas. But an inexperienced eye sees solid brackets in Lisp code. It is not easy to get used to Lisp-like languages, it would take us time. F #? Well, I don't want to involve .NET, for purely ideological reasons. Erlang, subjectively, seems like a heavyweight destined for other purposes. His merits are foolish, but why are they in such a specific task as the creation of a quest? Perhaps, only OCaml could argue with Haskell - as a close relative with similar syntax and comparable expressiveness. Only I see that Haskell, which was created as the best functional language, can wipe his nose — not now, but in the future. At least, one can hope for it, observing its life curve: now it rises sharply upwards. Many other reasons can be found; although in fact it doesn't matter why exactly Haskell. I know one thing: to write on it is a great pleasure, and the more pleasant that you realize: it is Haskell that is the cutting edge of programmer science.
')
Of course, in practice, Haskell loses both Erlang and Lisp, and even F #, the last of which, apparently, set out to conquer many .NET application programmers. Simon Peyton Jones, one of the creators of the Haskell language, even came up with an unofficial motto: “avoid popularity at all costs”. Hopefully, the series of these articles will not disappoint him too much. There is a possibility that someone, having read about Haskell, will begin to study it, and, having understood its philosophy, will try to apply it somewhere. While I was writing small test programs, I got the idea to make a parser and merger of traffic from telephone exchanges (I work in telecoms) on it — I was very attracted by the opportunity to write functional parsing, having spent a minimum of effort, - not like in C. I implemented this idea. The program was not perfect, with a peak load it requires a lot of memory - but its significant advantage is that having a working prototype, I can improve it and quickly adapt it to new conditions. The Haskell code is easy to redo, but this headache with painful debugging is already gone. And although this is not the merit of the language, but the total functional programming, I am inclined to associate exactly Haskell with the OP, and not anything else.
Speaking of practice. You should have seen how Haskell syntax is beautifully highlighted in GeSHi! Well, here's an example:

After all, is it really amazing lighting? Unfortunately, Habrahabr does not support any advanced tags, but only “font”. And what to do? Shovel the result, replacing everything with a “font”? You are tormenting. Or climb into the insides of GeSHi? But I do not like php! I didn’t like either of them, so I just wrote a Haskell parser-formatter in the evening. And, it seems, it works well. Despite the imperfection. Because of this, you will see the code in my articles almost as well highlighted as GeSHi does.
My quest project is called Adv2Game (Advanced Adventure Game). You will find the source code on
the project page (
git ). And the accompanying code for the guide, I will lay out
here (
git ). The name "Adv2Game" I chose by chance. The fact is that in Hackage Haskell repositories there is a simple quest advgame, - I borrowed some ideas from there and beat them in my own way. Now my quest is very far from completion, and I can not vouch that it will be completed ever. This, of course, is not good - leaving projects unfinished. I hope, nevertheless, that my articles will not be in vain, and someone thanks to them will bring their Haskell project to the end.
The literature for studying Haskell is diverse, but unfortunately, mostly in English.
Best-most English-speaking sources:
1. “Learn You a Haskell for Great Good!” (
Website ,
zip-archive of mht-files by chapters ).
2. "Real World Haskell" (
website ,
zip-archive of mht-files by chapters ).
3.
HaskellWiki (including a
list of all sorts of tutorials ).
4.
Haskell Planet .
Russian-language materials:
1. Partial translation of “Learn You a Haskell for Great Good!” On this blog by good people. (
[1] ,
[2] ,
[3] ,
[4] ).
2. The journal
"The Practice of Functional Programming" - in truth, a wonderful work!
3. Blogs of clever people writing in Haskell:
_adept_ ,
thesz ,
Alex Ott ,
yantayga .
Well, in search of adventure? ..
Content:
GreetingPart 1 - The ThresholdPart 2 - ForestPart 3 - PolyanaPart 4 - View of the canyonPart 5 - Hall