![]() Just like you can’t teach someone how to write by only giving them a dictionary, you can’t teach someone to use a Haskell library by only giving them a reference manual. Hackage is literally a list of function signatures with a couple of comments attached to each one. I want to make a series of blog posts about image processing and rendering in Haskell but it is almost impossible to learn how to actually use the available packages in Hackage ( ) without knowing how the libraries work ahead of time. The lack of good documentation about Haskell libraries is a challenge which I am currently facing, even after having learned how to write useful code in Haskell. The structure of a compiled Haskell program is much more recursive and much less sequential and you try to avoid mixing pure code with sequential statements, which are typically used for I/O. Interacting with the interpreter involves inputting sequential statements which get executed one after another. This is not the case in Haskell, because the ghci interpreter does not teach you what it takes to write a compiled Haskell program. In my Haskell for the Imperative series, I will take the approach of teaching monads as if they are a basic concept of Haskell programming that you should learn first and then introduce advanced features like if-statements, functional programming, and the do-notation.Īs a side note, in many languages the REPL or interpreter enables a beginner to get to the point where they can do something useful almost immediately. ![]() ![]() Most learning resources for beginners teach a lot of unnecessary functionality and syntactic sugar before they get to monads, so it can take several chapters of a book before you get to the point where you can actually write a meaningful program. In my opinion, the best way to get to the point where you can understand and write code with side effects, such as printing “Hello World!”, is to learn about monads as quickly as possible. I want to stress that useful code involves side-effects, and side-effects involve monads, which are often taught as an advanced feature of Haskell. I think that most programmers are interested in getting to the point where they can write an application that does something useful as quickly as possible. It is essential to stay motivated when learning a programming language which is why having some tangible goal in mind, usually some program which does something fun or useful, is so important for learning. Once you overcome this hurdle, learning the rest of the language just involves incremental improvements on what you already know. This is the reason why I include several worked examples of evaluation and substitution in Getting Started with Haskell. I knew before I started learning Haskell that pure functional code is equivalently expressive to imperative programming, but until I sat down and computed an example by hand, it was hard to comprehend. It takes a while just to come to terms with the fact that for every imperative program, you can write an equivalent program using evaluation and substitution. To someone coming from the world of imperative programming, the idea that you can compute something without modifying state sounds crazy. In my opinion, if you are learning Haskell starting from an imperative programming language this is the biggest hurdle you will face by far. I think that there are three factors which make learning Haskell more difficult than it should be: Since I’m still new to the language and I’ve recently overcome some of the hurdles in learning Haskell, I want to put them down in writing before I forget them. ![]() They sometimes require one more level of abstraction than you are used to, but once you become familiar with what they mean, they are no more complex than “class” or “function”. Learning Haskell requires coming to terms with a lot of scary words like “Currying”, “monads”, “monoids”, and “functors” but these are often just convenient abstractions that make programming easier. When you write a Haskell program it is much easier to predict what the behavior of the program will be than if it was written in most other languages. Haskell has a reputation for being arcane and difficult, but in my experience it is a language which is easy to reason about. ![]()
0 Comments
Leave a Reply. |