Haskell Quest Tutorial - Greeting
- Tutorial
Good afternoon, adventure lovers!
You, of course, played the text adventure game Zork. Do you still remember those weeks when you were looking for the entrance to the dungeon, or thinking how to get past the goblins with clubs. You remember how you waved your sword, you even tried various options for “hit self” and “kill self”. The program understood your commands - the result was predictable ... It was fun and amazing to study the Zork text world! And you, of course, wanted to create something like this with your own hands. So maybe try? Together? In this guide, 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 I were telling them 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 to learn the language. I am ready to answer all your questions if I can. Sophisticated Haskellists may find answers, explanations, and program code somewhere clumsy or incomplete. This is nothing: the farther into the forest,the worse 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. “Knowing the path and going through it is not the same thing.”
Why Haskell and not F #, OCaml, Erlang, Lisp ...? Haskell of these 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 levels. He has long occupied his niche, presented the art of programming with many ideas. But the inexperienced eye sees solid brackets in the Lisp code. Lisp-like languages are not easy to get used to, it would take our time. F #? Well, I do not want to attract .NET, - for purely ideological reasons. Erlang, subjectively, seems like a heavyweight intended for other purposes. Its merits are not great, but why do they need us in such a specific task as creating 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, so in the future. At least this can be hoped for by observing his life curve: now it rises sharply up. Many other reasons can be found; although it’s actually not important why Haskell is. I know one thing: writing on it is a great pleasure, and all the more pleasant that you realize: it is Haskell - the cutting edge of computer science.
Of course, in practice, Haskell loses both Erlang, and Lisp, and even F #, the last of which, apparently, aimed 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 his philosophy, he will try to apply it somewhere. While I was writing small trial programs, I became infected with the idea of making a parser and a merger of traffic from telephone exchanges on it (I work in telecoms) - I was very attracted by the opportunity to write functional parsing, spending a minimum of effort, not like in C. I implemented this idea. The program turned out to be not perfect, at 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 to new conditions. The Haskell code is easy to redo, but this headache with excruciating debugging is no longer there. And although this is due not so much to the language as to the whole functional programming, I am inclined to associate Haskell with FP, and not something else.
Speaking of practice. You should have seen how beautifully the Haskell syntax is 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 "font"? You are suffering. Or get into the insides of GeSHi? But I do not like php! I didn’t like either one, so I just wrote a parser formatter in Haskell over the evening. And it seems to work well. Despite the imperfection. Thanks to this, you will see the code in my articles almost as well highlighted as GeSHi does.
The project of my quest is called Adv2Game (Advanced Adventure Game). You will find the source on the project page ( git) And the accompanying code for the manual I will post here ( git ). The name "Adv2Game" I chose by chance. The fact is that in the Hackell Hackage repository there is a simple advgame quest - I borrowed some ideas from there and beat them in my own way. Now my quest is very far from complete, and I can not guarantee that it will be completed ever. It is, of course, not good to leave projects incomplete. Nevertheless, I hope that my articles will not be in vain, and someone thanks to them will bring their project to Haskell to the end.
The literature for learning about Haskell is diverse, but, unfortunately, mostly in English.
The very best English sources:
1. "Learn You a Haskell for Great Good!" ( site ,zip-archive of mht-files by chapters ).
2. "Real World Haskell" ( site , zip-archive of mht-files in chapters ).
3. HaskellWiki (including a list of all kinds of manuals ).
4. Haskell Planet .
Russian-language materials:
1. Partial translation of “Learn You a Haskell for Great Good!” on this blog are good people. ( [1] , [2] , [3] , [4] ).
2. The journal "The Practice of Functional Programming" - truly wonderful work!
3. Blogs of smart people writing in Haskell: _adept_ ,thesz , Alex Ott , yantayga .
Well, looking for adventure? ..
Contents:
Greeting
Part 1 - Anticipation
Part 2 - Forest
Part 3 - Glade
Part 4 - View of the canyon
Part 5 - Hall
You, of course, played the text adventure game Zork. Do you still remember those weeks when you were looking for the entrance to the dungeon, or thinking how to get past the goblins with clubs. You remember how you waved your sword, you even tried various options for “hit self” and “kill self”. The program understood your commands - the result was predictable ... It was fun and amazing to study the Zork text world! And you, of course, wanted to create something like this with your own hands. So maybe try? Together? In this guide, 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 I were telling them 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 to learn the language. I am ready to answer all your questions if I can. Sophisticated Haskellists may find answers, explanations, and program code somewhere clumsy or incomplete. This is nothing: the farther into the forest,
Why Haskell and not F #, OCaml, Erlang, Lisp ...? Haskell of these 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 levels. He has long occupied his niche, presented the art of programming with many ideas. But the inexperienced eye sees solid brackets in the Lisp code. Lisp-like languages are not easy to get used to, it would take our time. F #? Well, I do not want to attract .NET, - for purely ideological reasons. Erlang, subjectively, seems like a heavyweight intended for other purposes. Its merits are not great, but why do they need us in such a specific task as creating 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, so in the future. At least this can be hoped for by observing his life curve: now it rises sharply up. Many other reasons can be found; although it’s actually not important why Haskell is. I know one thing: writing on it is a great pleasure, and all the more pleasant that you realize: it is Haskell - the cutting edge of computer science.
Of course, in practice, Haskell loses both Erlang, and Lisp, and even F #, the last of which, apparently, aimed 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 his philosophy, he will try to apply it somewhere. While I was writing small trial programs, I became infected with the idea of making a parser and a merger of traffic from telephone exchanges on it (I work in telecoms) - I was very attracted by the opportunity to write functional parsing, spending a minimum of effort, not like in C. I implemented this idea. The program turned out to be not perfect, at 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 to new conditions. The Haskell code is easy to redo, but this headache with excruciating debugging is no longer there. And although this is due not so much to the language as to the whole functional programming, I am inclined to associate Haskell with FP, and not something else.
Speaking of practice. You should have seen how beautifully the Haskell syntax is 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 "font"? You are suffering. Or get into the insides of GeSHi? But I do not like php! I didn’t like either one, so I just wrote a parser formatter in Haskell over the evening. And it seems to work well. Despite the imperfection. Thanks to this, you will see the code in my articles almost as well highlighted as GeSHi does.
The project of my quest is called Adv2Game (Advanced Adventure Game). You will find the source on the project page ( git) And the accompanying code for the manual I will post here ( git ). The name "Adv2Game" I chose by chance. The fact is that in the Hackell Hackage repository there is a simple advgame quest - I borrowed some ideas from there and beat them in my own way. Now my quest is very far from complete, and I can not guarantee that it will be completed ever. It is, of course, not good to leave projects incomplete. Nevertheless, I hope that my articles will not be in vain, and someone thanks to them will bring their project to Haskell to the end.
The literature for learning about Haskell is diverse, but, unfortunately, mostly in English.
The very best English sources:
1. "Learn You a Haskell for Great Good!" ( site ,zip-archive of mht-files by chapters ).
2. "Real World Haskell" ( site , zip-archive of mht-files in chapters ).
3. HaskellWiki (including a list of all kinds of manuals ).
4. Haskell Planet .
Russian-language materials:
1. Partial translation of “Learn You a Haskell for Great Good!” on this blog are good people. ( [1] , [2] , [3] , [4] ).
2. The journal "The Practice of Functional Programming" - truly wonderful work!
3. Blogs of smart people writing in Haskell: _adept_ ,thesz , Alex Ott , yantayga .
Well, looking for adventure? ..
Contents:
Greeting
Part 1 - Anticipation
Part 2 - Forest
Part 3 - Glade
Part 4 - View of the canyon
Part 5 - Hall