46
votes

I have had previous exposure to imperative languages (C, some Java) however I would say I had no experience in programming. Therefore: treating me as a non-programmer, would Haskell be suitable as a first language?

My interests in Pure Mathematics and CS seem to align to the intention of most Haskell tutorials, and although i can inherently recognise the current and future industry value of imperative programming, I find the potential of functional programming (in as much as it seems such a paradigm shift) fascinating.

I guess my question can be distilled as follows - would a non-programmer have to understand imperative programming to appreciate and fully utilise functional programming?

Some references:

11
What is your aim in learning to program? Just for the sake of it, or is there something particular you want to do?Grant Crofton
I think curiosity is a big part of it, and future proofing - i'd like to have an understanding of a technology that seems to be playing a big part in how we will program in days to come (caveat - this is opinion). To answer your question just for the sake of it, however i am interested in amatuer cryptography so whatever language i learn would have to adapt to mathematical concepts fairly well so i could integerate it with that.Alex
One reason Grant's question was important, by the way, is that the answers to these things depend on whether you want to become a good programmer, or whether you want to learn enough programming to do something else. If you are in the second category, the answer is usually to learn what you're going to use, and don't worry about anything else until you have another need. If in the first, you're going to have to learn several languages to be really good, so which is the first matters less, and may as well be selected for pedagogical reasons.David Thornley

11 Answers

20
votes

I'll go against the popular opinion and say that Haskell is NOT a good first programming language for the typical first-time programmer. I don't think it is as approachable for a raw beginner as imperative languages like Ruby.

The reason for this, is that people do not think about the world in a functional manner. When they see a car driving down the street, they see the same car, with ever-changing mutable state. They don't see a series of slightly different immutable cars.

If you check out other SO questions, you'll see that Haskell is pretty much never mentioned as a good choice for a beginner.

However, if you are a mathematician, or already know enough about programming to understand the value of functional programming, I think Haskell is a fine choice.

So to summarize, I think Haskell is a perfect fit for you, but not a good fit for the typical beginner.

EDIT: Thanks for the insightful comments. Owen's point that people think in a multi-paradigm manner is very true. This strengthens my belief that a multi-paradigm language like Ruby would be easier to pick up, and has the added benefit of exposing the student to both imperative and functional thinking. Haskell is decidedly not multi-paradigm.

Chuck mentioned Haskell's sophisticated type system which is another great point. While I personally prefer statically typed languages, using a dynamic language allows a beginner to ignore that piece of the puzzle until they are curious enough to find out what is going on behind the scenes. Haskell's type system, while elegant, is in your face from day 1.

33
votes

Well, the existence of SICP suggests that functional languages can be used as introductory material. Scheme is perhaps more approachable than Haskell, however.

Haskell seems to have a reputation for being "difficult" to learn, but people tend to forget that classic imperative programming is difficult to learn as well. Many people struggle at first with the concept of assigning a value to a variable, and a surprising number of programmers never actually do become comfortable with pointers and indirect references.

The connections between Haskell and abstract mathematics don't really matter as much as people sometimes assume, but for someone interested in the math anyway, looking at the analogies might provide an interesting bonus.

29
votes

There has been at least one study on the effects of teaching Haskell to beginner programmers:

With the following abstract:

We argue that teaching purely functional programming as such in freshman courses is detrimental to both the curriculum as well as to promoting the paradigm. Instead, we need to focus on the more general aims of teaching elementary techniques of programming and essential concepts of computing. We support this viewpoint with experience gained during several semesters of teaching large first-year classes (up to 600 students) in Haskell. These classes consisted of computer science students as well as students from other disciplines. We have systematically gathered student feedback by conducting surveys after each semester. This article contributes an approach to the use of modern functional languages in first year courses and, based on this, advocates the use of functional languages in this setting.

So, yes, you can use Haskell, but you should focus on elementary, general techniques and essential concepts, rather than functional programming per se.

There are a number of popular books for beginner programmers that also make it an attractive target for teaching these elementary concepts, including:

  • "Programming in Haskell"
  • "The Craft of Functional Programming"

Additionally, Haskell is already widely taught as a first language. -- but remember, the key is to focus on the core concepts as illustrated in Haskell, not to teach the large, rich language that is Haskell itself.

13
votes

Eleven reasons to use Haskell as a mathematician
I cannot write it better than that. But to summarize:

  • Haskell is declarative and mathematics is the ultimate declarative language, which means that code written in Haskell is remarkably similar to what you would write as a mathematical statement.
  • Haskell is high-level, no need to know details about caches, memory management and all the other hardware stuff. Also that means short programs which is always good.
  • Haskell is great for symbolic computation, algebra, logic ...
  • Haskell is pretty :)

To answer your question: you'll have no problem to start with a functional language as a mathematician with no programming experience. Actually it's the better choice, you won't have to repair the brain damage you would get from C/Java/whatever.
You should also check Mathematica. Some people tend to dislike it since it is a commercial closed-source product, but I think it's a pretty good environment for doing mathematics.

12
votes

If you haven't had any experience at all, it will in fact be easier for you to be productive in functional programming, especially PURE functional programming. I'm an immigrant from imperative to function, I had to deal with having to forget about 80% of what I learned to be productive in Haskell.

In contrast, it's easier to switch from functional to imperative later on.

4
votes

On one hand, I think Haskell is nice as a first language, but I suppose, for anyone seriously interested in programming, it should be learned in parallel with C or after C (or an assembly). C is necessary to learn what's happening under the hood, what are the costs of doing this and that, and finally appreciate the usefulness of higher level of abstraction and automatic resource management. I think when being exposed to both C (as a low-level imperative language) and Haskell (as a high-level functional language), most students will find Haskell both practical and expressive.

On the other hand, I think that programming is a craft. It is a practical activity, and it is important to learn the joy of creating something new, useful or interesting. So you need to get things done. And the easiest way for this is using a language which has tools for your problems, i.e. libraries for your data formats, algorithms for your kind of problems. And at this point, Python (or Ruby) may be a better choice, because Hackage still lags behind PyPI in many areas (and say, how many days you need to teach a novice to manipulate an image, or to plot charts in Haskell?).

So, my opinion is that some exposure to low-level imperative programming is necessary (to OOP, probably, not). Then you can understand the value of Haskell. But to get things done, and to quickly become productive, Python is a better choice for beginners. Haskell requires a few weeks before it becomes your tool.

3
votes

I would say that it is suitable as a first language, and that having learned an imperative language first would probably only interfere with the learning process (since it requires lots of unlearning first).

As a caveat, I would add that a functional language principles would probably be best understood by someone with a mathematical background, as the concepts are abstract mathematical ones.

I know that many schools do teach it as a first functional language, but not as a first language.

3
votes

Yes it is. Real World Haskell is a great way to get into it http://book.realworldhaskell.org/

1
votes

I would hesitantly say "yes" except for the fact that in learning, finding someone as a mentor or tutor would be a much less daunting task if you chose a more imperative language to start programming. Might I suggest R or Python (with NumPy and SciPy) instead?

1
votes

No.

It's very easy for a haskell98 program to be clearly understood. LYAH is a great tutorial for people with no experience but trying to prevent a learner from stumbling on extensions x, y z is gona be tricky. Soon they start to explore and become overwhelmed with advanced programming/mathematical concepts which are much harder to understand but need to be understood to read other's code.

If every piece of haskell was written in just haskell'98/'10 I would probably say yes though.

0
votes

Without necessarily addressing the question as such, I would add: if you find haskell's persnicketiness too hard, do not be discouraged.

There are other programming languages, even functional ones, which are late bound.