Slashdot Log In
Why Lazy Functional Programming Languages Rule
Posted by
ScuttleMonkey
on Friday September 19, @11:18AM
from the laziness-is-the-mother-of-all-invention dept.
from the laziness-is-the-mother-of-all-invention dept.
Da Massive writes "Techworld has an in-depth chat with Simon Peyton-Jones about the development of Haskell and his philosophy of do one thing, and do it well. Peyton-Jones describes his interest in lazy functional programming languages, and chats about their increasing relevance in a world with rapidly increasing multi-core CPUs and clusters. 'I think Haskell is increasingly well placed for this multi-core stuff, as I think people are increasingly going to look to languages like Haskell and say 'oh, that's where we can get some good ideas at least', whether or not it's the actual language or concrete syntax that they adopt.'"
Related Stories
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Full
Abbreviated
Hidden
Loading... please wait.

I would have RTFA (Score:5, Funny)
But I was too lazy to click on 13 pageviews.
Reply to This
Too constrained and academic (Score:5, Insightful)
A separate, but related problem is that the community doesn't seem interested in practical use of it - there aren't lots of bindings to libraries to make easy things easy. Heck, even doing i/o at all isn't really supported very well. Functional programming is very good for the pure computer science part of programming, but unfortunately that's going to make up less than half of any given program. You also need to be able to interface.
So I think the quote in the summary is right: people won't be adopting Haskell or similar pure-functional languages any time soon. What will happen is the next generation of dynamic languages will adopt the best features from functional programming; we've seen that happen already in python and ruby, and it'll happen again. And people will start using them there.
Reply to This
Re:Too constrained and academic (Score:5, Interesting)
A separate, but related problem is that the community doesn't seem interested in practical use of it
Really? That's why there's a new book called Real World Haskell [realworldhaskell.org]. The IRC channel on freenode is one of the largest on the entire network, and full of people doing real world things with haskell.
there aren't lots of bindings to libraries to make easy things easy.
I call FUD. The Hackage database [haskell.org]has literally hundreds of libraries sat there ready for you to use. And if you really need something that isn't there, the FFI is mature, and very easy to use.
Reply to This
Parent
Re:Too constrained and academic (Score:5, Interesting)
You also need to be able to interface.
Which is exactly why I find Scala [scala-lang.org] to be interesting. Note: I haven't had time to learn or use it yet, but the design concept there is very interesting.
Reply to This
Parent
Re:Too constrained and academic (Score:5, Interesting)
Very true, I did a large project in Haskell for a CS class once the three of us working on it hated the language after we were done.
Before that we were pretty happy with Haskell, because the programming assignments leading up to the final project were all fitted to the language, but the instant we had to do something that wasn't, we realized what a mess it is.
Reply to This
Parent
Re:Too constrained and academic (Score:5, Interesting)
No, I mean it is a true, honest to God, functional language. If you check Wikipedia, for example, you will see it listed as "Multi-paradigm: prototype-based, functional, imperative, scripting".
See, most people look at the C-style syntax and think it means that Javascript is a C-style language. Then they get frustrated when the C-stlye code they write looks like crap. Instead, they should be coding with closures and lambda, much like they would with a LISP program. The result is a far more sophisticated program that performs more work with greater elegance than a C-style equivalent.
I highly recommend Douglas Crockford's "The JavaScript Programming Language" [yahoo.com] introduction to the language if you're not familiar with Javascript's functional aspect.
Reply to This
Parent
Why they don't rule: (Score:5, Funny)
Reply to This
Re:Why they don't rule: (Score:5, Informative)
The picture in the linked article is missing a beard.
I was going to mod you funny, then I thought maybe a lot of people wouldn't get the beard reference [microsoft.co.il], so I decided to post instead. Anyone else want to mod parent funny?
Reply to This
Parent
Re:Why they don't rule: (Score:5, Funny)
Anyone else want to mod parent funny?
Yes, I will!
Oh crap.
Reply to This
Parent
It's not for dumb people (Score:5, Insightful)
I haven't really been able to figure out how to do anything significant in Haskell. But I suspect that one day a language more like haskell and less like C will end up being the most popular. Monads and all that kind of confuses me.
I think it helps if you have a strong math background and are comfortable with Lambda calculus. I'm just an old C hacker and haven't used any real math in like 10 years, so I'm not that effective in Haskell :(
Reply to This
Re:It's not for dumb people (Score:5, Funny)
Don't worry.
In a few years you will see c++++ which will be c++ with functional programing tacked on. Of course you will also see Functional Object C but only Apple will use that.
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Insightful)
I spent a whole term at uni learning Miranda, which is similar to Haskell, I really liked it. I have *never* seen it being used since. To my mind they both belong in the category 'interesting, but pointless'.
Its not just because they're old. If age was what killed languages, C and Lisp would be long dead. There just isn't anything I could do with either that I wouldn't be able to do more easily with another more 'mainstream' language.
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Insightful)
I call FUD. There's a lot of things that Lazy functional languages make easy, that mainstream languages don't. Here's just a few examples: Infinite data structures can be handled naturally.
Might that be because infinite data structures don't often exist in mainstream and/or commercial software applications?
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Insightful)
Might that be because infinite data structures don't often exist in mainstream and/or commercial software applications?
Might that be because mainstream programming languages don't support infinite data structures?
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Insightful)
Might that be because infinite data structures don't often exist in mainstream and/or commercial software applications?
Sure they do. On my computer, there's an infinite stream of ethernet frames arriving, an infinite stream of video frames leaving, an infinite stream of keyboard events arriving, etc.
The thing about functional languages, and strict lazy functional languages like Haskell, is that the underlying principles are quite different from procedural languages like C. In C, you tell the computer to do things. In Haskell, you tell the computer the relationships between things, and it figures out what to do all on its own.
Personally, I suck at Haskell --- I'm too much of a procedural programmer. My mind's stuck in the rails of doing thing procedurally. But I'd very much like to learn it more, *because* it will teach me different ways of thinking about problems. If I can think of an ethernet router as a mapping between an input and output stream of packets rather than as a sequence of discrete events that get processed sequentially, then it may well encourage me to solve the problem in a some better way.
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Insightful)
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Informative)
Absolutely, and this is why there's one of freenode's biggest IRC channels, a pair of mailing lists with thousands of subscribers, and the Hackage [haskell.org] library/tool repository just waiting to help you solve your real world problem. Be it Compiler building [haskell.org], version control [darcs.net], writing interpretters for popular imperrative languages [perlfoundation.org], Writing 3D shooters [haskell.org], or a whole host of other tasks.
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Insightful)
I call meme misuse.
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Insightful)
Here's a function that generates the infinite list of fibbonacci numbers: fibs x y = x : (fibs y (x + y))
You have just demonstrated thermian's point.
How often do you actually need to generate infinite sequences? I have never needed to do that outside of a functional programming class.
I'm a big fan of alternative programming languages, I've used some 20 or so since I started 20 years ago. I did a fair amount of commercial Prolog development after I left university, I really like Prolog. It makes certain things really easy and it's a joy to code certain types of solutions in, but I'm never going to write a web-app, or a word-processor in Prolog.
Many of these languages are very clever when it comes to doing certain things, but how often do you actually need to do those things?
The truth is that the vast majority of the software out there does pretty dull, mostly procedural jobs. That's why the main languages in use are just dull variations on the procedural, C/Java/Perl style. No matter how much maths geeks go on about functional programming, procedural systems will always be more suited and easier to use for most of the problems out there.
That isn't to say there is no place for these alternative languages, but it's a smaller one which you probably won't see very often.
Paul
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Insightful)
Haskell only evaluates what it has to -- this program for example which looks up the 3000th element of the sequence will not compute the complexCalculation on the 2999 fibbonaccis before hand like a traditional program would
And then when you actually do use the other values you program is ridiculously slow because the generator function is recalculating the fibonacci number over and over again.
Except you hope that Haskell automatically memoizes the results, but that destroys your smp performance as the CPUs contend over the result cache. So maybe you have separate caches per thread. Then you program grows larger and all the memoization takes too much memory and the system start dropping out results (3000th fib is what 520? bytes). Then you have to go back and tell it to keep the results longer for that function.
In the end maybe you just make it a list that's precomputed.
But that's really beside the point, because you can do the exact same thing in Smalltalk, Ruby, JavaScript, etc, with most of the same costs and benefits. So really the question is, what makes it better than Smalltalk? It's faster at maths, but that's about it. But it has a harder/alien paradigm, the syntax is foreign, etc. Maybe that's why afaik mainly Haskell is only being used by people that crunch numbers ?
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Interesting)
Depends on how you determine "easy to read". The main difference between Haskel and say C is that Haskel is very dense while C is not so much, so one line of Haskel holds a lot more information then C, which of course makes look like its Haskel harder to read, since understanding a line of code requires effort, while its trivial in C. However that line of Haskel might contain the same information as a whole function in C and reading that whole function in C might turn out harder then comprehending that single line of Haskel.
All that said, I don't consider the syntax of Haskel very good, lack of parenthesis around function arguments certainly doesn't help readability and the error messages can be rather obscure as well.
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Insightful)
It's only difficult to read if you don't know it.
That is true of almost any language. The point is that there's nothing those languages can do that can't be done, often more easily, with the current crop of popular languages. Elegance cannot beat convenience in the workplace, or in most at any rate.
All that aside, how many Haskell programing jobs have you seen advertised lately? Like it or not, that's what decides which languages people use.
That's why I have to deal with languages I'd prefer to never use, because that's what pays the rent. In my own time I use C.
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Interesting)
I've seen quite a few Haskell jobs advertised recently actually, I even got one of them :).
Reply to This
Parent
Re:Mmmm, Kay. (Score:5, Interesting)
The point is that there's nothing those languages can do that can't be done, often more easily, with the current crop of popular languages.
At University, I studied SML, and came out with a opinion similar to yours concerning functional languages. But when I started to learn Haskell on my own, really learn it, I found that all the concepts in my CompSci courses that seemed so pointlessly complex before, just fell neatly into place.
I'll give you an example of a case where my solution in Haskell to a problem was rather better than any solution I came up with in C#. A while ago I was designing a program to export some hierarchical data held in a database to XML. Because SQL resultsets are 2D grids, I needed a way of converting a 2D grid into a list of fixed-depth tree structures.
In Haskell, the solution is two lines of code, and assuming you know Haskell pretty well, it's fairly clear as well:
I'd be interested to see if you could mirror the functionality in one of the 'popular' languages you mentioned. Perhaps something in Java?
Reply to This
Parent
Re:Why "lazy"? (Score:5, Informative)
They're "lazy" because they don't do any work until necessary. For example, a function can return an infinitely long list, but only the elements you request will actually be calculated. Or, to compare them to Python, it's like having everything function like an iterator.
Reply to This
Parent