views:

1018

answers:

10

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 Mathmatics 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:

+3  A: 

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.

Oded
I intend to include my studies of functional programming with my studies of pure mathematics. Can you give examples of langauges used as a first functional langauge?
Alex
@Alex - Apart from Haskell, Scheme is (was?) used in MIT.
Oded
Thankyou, i am aware of scheme ML and considered that as another option, i may well lead into it after spending sometime with haskell
Alex
+3  A: 

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

Alain O'Dea
Thanks, i had looked at RWH, however i must admit i think my understanding of programming may require a more elementary approach than that text
Alex
RWH is great, but it is pitched more at programmers from other languages. [LYAH](http://learnyouahaskell.com/) might be a better intro.
camccann
I did not like RWH, I'm trying to learn Haskell again with the Thompson book and finding much more success.
Evan Carroll
I got hooked with http://www.haskell.org/soe/ – which is a mind-bender of a book but fun! – but I was glad I had RWH on hand some years afterward to fill in a lot of the holes.
Owen S.
+1  A: 

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?

wheaties
I prefer self-study both in terms of time and understanding, although i do agree that there is value in mentoring i feel the community can/should provide that (regardless of the language)
Alex
Bah, who needs a mentor when you have SO?
camccann
+6  A: 

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.

LukeN
Thanks for the vote of confidence!
Alex
I'm learning Haskell too! But, this is certainly a platitude *had to deal with having to forget about 80% of what I learned to be productive in Haskell.* If being productive in one language requires you to forget stuff you've learned rather learn more stuff -- you're doing it wrong.
Evan Carroll
@Evan That's just the way it is. Functional programming is fundamentally different from imperative programming. I didn't *forget* it in terms of forgetting, but as in knowing what certain stuff is NOT in functional programming, like `return` in Haskell vs `return` in C, or assigning variables (as there's no variables in Haskell). If I had really forgotten all that, of course I would have done it wrong :)
LukeN
+15  A: 

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.

dbyrne
Thankyou for a very considered response!
Alex
I agree with your conclusion, but not your reasoning. People don't naturally think about the world in a way that lends itself to computer instructions at all. Because most people learn imperative programming first, they develop a mapping between that and their model of the world. It's not much different from how the Greeks believed Greek words were the "true" names of things and other languages were less intuitive. Haskell is questionable as a first language, though, just because it's so big that it takes *years* to really get and it's so heavily based in type theory.
Chuck
Greeks also believed that the brain was a knot to stop the spinal cord from falling down, and that their eyes shot out frekin laser beams, and that the first four numbers were divine truth -- just because the Greeks are wrong about a pretty unrelated point doesn't mean that all paradigms map to human thought patterns with the same degree of ease or that his point about cars and mutable state should be discarded.
Evan Carroll
The way people naturally think about the world maps very poorly onto structured imperative programming. It maps even *more* poorly onto pure functional programming. Thinking in ways conducive to programming is and always will be a very *unnatural* activity.
camccann
@camccann, I'm not sure I agree with the statement but I like that you at least hint that logically both of them are are not on the same footing (I don't even care to takes sides).
Evan Carroll
@camcann: I've heard anecdotally that people with imperative programming experience tend to have a harder time learning Scheme than people learning it as a first language. For the professional programmer, I'd advise learning both fairly early on; for somebody who just wants to program things, pick what you're more likely to use.
David Thornley
If I'm talking about nouns in the real world, I'll be talking about objects, state, mutable properties, and invariants. If I'm talking about verbs, especially sequences of actions that I need to chain together to achieve something, I'll express it in a rather functional way, since breaking it down to loops and iterators would be a pain. When I write down a recipe, it's going to be in an imperative mode. Ladies and gentlemen of the jury, I submit that people think – who knew? – in a multi-paradigm way. That being said, translating those modes into programs is still almost always a challenge.
Owen S.
People walking down the street in Miami and seeing a car don't expect that somebody in Utah can wave a magic wand and poof! the car is now an airplane. That's what you get with unrestricted mutation.Functional programming isn't about abandoning mutation when it makes sense, but it *is* about local reasoning.People with high school algebra also don't see the series of equations "x = 1", "x = 2" as making sense, and they certainly don't see the equation "x = x + 1" as making much sense.So I'd argue that people do think equationally.
sclv
+19  A: 

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.

camccann
+8  A: 

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.

Daniel Velkov
+13  A: 

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.

Don Stewart
Thankyou that is a very well put together response, however i should point out that the elementary ideas of programming and computer architecture are not alien to me - i simply wondered whether or not i should ground this elementary understanding first imperitivley before attempting to grasp them functionally.Iv just got the following and from first impressions highly recommend it! http://www.amazon.co.uk/exec/obidos/ASIN/0954300696/textsincomput-21
Alex
A: 

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.

Tim Matthews
Just to play devils advocate without trying to turn this into a discussion board...What about the validity of Haskell for teaching exactly these kind of concepts?
Alex
I think it would be great for that
Tim Matthews
+2  A: 

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.

jetxee