Why Lazy Functional Programming Languages Rule
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.'"
But I was too lazy to click on 13 pageviews.
Hascal, and other functional languages may be good for multi-core development. However not to many programmers program in them... Plus I find they do not scale well for larger application. Its good for true computing problem solving. But today most developopment is for larger application which doesn't necessarly solve problems per-say but create a tool that people can use.
If something is so important that you feel the need to post it on the internet... It probably isn't that important.
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.
I am trolling
The picture in the linked article is missing a beard.
If you can read this, I forgot to post anonymously.
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 :(
“Common sense is not so common.” — Voltaire
Slashcode.
uniq: command not found
And it is a suck-up functional programming language.
The output of all my Haskell programs is: "Gee Mrs. Cleaver. You look nice today."
13 pages? And no print version? No wonder no one reads articles on Slashdot.
Seems like "interesting" is the author's favorite word
Why are they referred to as "lazy"? Is it simply because their have a singular purpose, (usually) unable to multitask?
Harold
for me to poop in!
This must be some use of the word "rule" that I was previously unaware of!
Wherever you are is the handicapped stall by definition. Now go back to sleep.
This is why I've started to learn Erlang. ;)
The first 4 pages are a nice look at the history of Haskell (which I knew nothing about). The rest of the article gets a little technical for someone with no experience or real world understanding of it.
When I saw the size of the article it was a little intimidating, but there is a wealth of information in it and by the end I found myself googling for more.
How widely used is Haskell?
ed duval the very last person
"Unfortunately it makes it almost impossible to do things they didn't expect"
Name just ONE such thing. This is FUD, plain and simple. And it doesn't look like you've ever even learned haskell to be making such claims.
"A separate, but related problem is that the community doesn't seem interested in practical use of it"
Yeah, nobody is doing practical stuff like writing the best X11 window manager ever, or an extensible editor, or web application servers, or IRC bots or distributed version control systems in haskell. Oh wait, that's exactly what people are doing. Oops, you are a liar!
"there aren't lots of bindings to libraries to make easy things easy"
Maybe not as many as perl, but easily just as many as ruby. There's tons in hackage.
"Heck, even doing i/o at all isn't really supported very well"
Are you fucking kidding me? Clearly you have never bothered to try and are just repeating bullshit you heard trolls spew. I/O is simple and easy, and it even uses a familiar imperative style syntax.
"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."
Actually, most people realize when they try that about 90% of their program can be pure functional code with far fewer bugs and much easier to maintain code. So they write the core program in nice pure functional haskell, and then write the 10% in haskell as well using the imperative style syntax for monads. See xmonad for a good example of this approach, and how stable the resulting wm has been as a result.
We can see this philosophy in C where, except where huge data structures are involved, it is best to make a copy of data rather than work to work on someone else's copy. Likewise functions do one thing, do it well, and, again except for huge data structures, return a copy. Memory is manually allocated, and deallocated, possibly from the functions local heap.
It is interesting to me how it all comes back to just best practices. Make sure you know how much memory you need. Make sure you are only doing what needs to be done right now. Make sure the interfaces are clear. If data is ready, then it should be ok to work on it. To me functional programming is what happens after data models, or objects, are defined. Once the data structure is defined, you can treat it as stateless immutable input. Output is a another structure. Again, the only limitation is if the object is so large that duplicating become a cost performance issue.
"She's a scientist and a lesbian. She's not going to let it slide." Orphan Black
most of us are lazy but functional also.
It figures that this article would be an interview. That way Simon Peyton-Jones didn't need to evaluate the answer to any question until it was asked.
Features of Haskell I really enjoy are how it handles constructors, pattern-matched function arguments, user-definable infix operators (with configurable precedence!) and the way it handles higher-order programming and lazy programming. But I never got monads...
Of course, my philosophy is that that's not necessarily a bad thing. Haskell is, IMO, a domain-specific language specialized on functional problems. I feel it's better to have different specialized languages working together well, rather than have one that attempts to do everything...
Bow-ties are cool.
Just because a language is not widely used outside academia does not mean it isn't a good teaching tool. You can pick up a new language in a few weeks, but a strong understanding of the fundamentals lasts forever. In a teaching setting, you want a language and dev tools that do not get in the way of illustrating the concepts.
At my university, a professor chose C++ to teach computational linguistics to non-programmers. HUGE mistake! We spent about 80% of the course learning C++ badly, rather than linguistics well. The CS department, wisely I think, taught its newbies in LISP.
What's the difference between a functional language like Lisp and a lazy functional language?
Just asking.
Could this be the year of Haskell in the developer's tool box?
Copyright infringement is "piracy" in the same way DRM is "consumer rape"
One thing in Haskell that always intrigued me was the idea of combinatorial parsers - a parser that accepts a string and yields not a single parse tree, but all possible parse trees based on the language rules... Simple implementations of those can be implemented in Haskell pretty straightforwardly. Combinatorial parsers for individual rules are stuck together - and while rules may generate a bunch of possible parse trees these are culled by successive rules...
I don't know too much about the practical efficiency of these - but in terms of how they're expressed I think they're great...
Bow-ties are cool.
And eat up after licking my fingers clean of poo-dinglers!
...is the one with the newspaper over its face, snoring in the corner, cans of soda piled up on the desk. The functional language is the one that has finished psychotherapy, is fully alert and active, and has a far higher risk of suffering a heart attack from overwork.
It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
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.
Monads, lambda, calculs...arrr, matey, now I know why Haskell's such a bloody mess - Neal Stephenson wrote it! That be why it seems good at first and falls apart at the end.
the fib example given isn't tail recursive. Actually, it's usually not a good idea to use tail recursion in Haskell since it can force you into strict evaluation when you don't need it.
I wouldn't say it's just slashdot. Functional languages have always had a stigma about them. Why else do you think "C took off so much?
I want one that will work hard for me!
That is all.
I have never found any practical use for the Fibonacci sequence. Ever. Not even for modeling snail shell formation for a malacologist, where you'd think it would be handy.
How do you parse a free form string that contains a person's name, typed in by someone being paid minimum wage, and determine the the probability that the name matches input from a cheap microphone? That's a better example, show me how Haskell makes that easier than some other language.
That underlying C code is what needs to be written carefully, because you use Haskell itself to write its own compiler.
There's a Haskell compiler written in Haskell already. Where does C fit in to that?
After the 'l' and before the 'o'.
Don't you mean "After the 'g' and 'h'"?
Bow-ties are cool.
Ill tell you from experience that while Haskell may be difficult to pick up and program efficiently in, if your program is going to be multi-threaded and ran on multiple processors it will be much safer, easier to debug, and less likely to run across nasty race conditions. With the push for these types of applications the move to functional languages is not very surprising, and although there is a slight performance loss to a language like C++ the ability to run reliably on multiple cores or an distributed array of servers kinda makes up for it.
How is that better than doing (or basically the same in Java/C/perl/ruby/etc.):
I hate to say "you're missing the point" because I feel that's unreasonably dismissive - though I kind of feel you are...
IMO the point isn't necessarily that one method is "better" than another - it's that this idea represents an important and useful way of approaching programming problems. If you understand the style you can appropriate it - it becomes a useful concept for expressing problems and their solutions.
So for instance - while you may not use recursion in C for general problem solving (due to the lack of tail-recursion optimizations which turn the thing into a loop) - understanding the recursive expression of a problem is useful for structuring your solutions, understanding what assertions must be made with respect to the state of the data at what points in the code, etc. - even if you structure your solution as a loop rather than a recursion.
And it should be noted that you can implement infinite sequences in C++, etc. - generally the way to do this is with iterators, and the use case would be for feeding those iterators to algorithms that expect iterators... What Haskell brings to the table is that it encourages you to think of problems and solutions in those terms - learn the method and what you can do with it, how it affects the expression of your code - if you find it a useful idea it's easy enough to implement in most object-oriented languages...
Bow-ties are cool.
The key to being a good software engineer is doing just enough to get paid. This is too much.
Be professional. Write simple. Be understandable. Recursion as a primary control structure violates at least two of the latter.
Ironically, the metaphor made here works... While vulgar (and therefore maybe flamebait,) it's not really off topic.
The same way they should measure the productivity of any team of programmers: are they able to solve the problem they're given within time and budget constraints. "Lines of code" is not a good measure of productivity in any language.
There have been functional programming languages that actually work well for high performance computing. One of them is called SISAL. Unfortunately, the FP community didn't care and SISAL's funding was canceled.
Haskell is largely an academic exercise: cute but hard to use and slow. Functional programming will become ever more important in the future, but it won't look anything like Haskell when it meets the real world.
I've seen the Fibonacci sequence used to show worst case input scenario in at least one algorithm.
Yes, and now, why don't you write something that computes a digital filter over an audio signal in Haskell and compare its performance and resource usage to the C version. Spend as much time as you like. It's infinite streams, it's recursive, it should be easy, right?
No matter how much time you invest, you cannot get Haskell code to run as fast as well-written C code; not even close.
The problem with languages like Haskell is that they make easy things easier, and the stuff that actually takes development time in real-world systems hard or impossible.
I wish there were high performance functional programming languages, I really do. But people like the Haskell developers have always ignored those needs. Until language designers like that start taking real world needs seriously, FP will not catch on.
Thoughts on Haskell, from a Haskell programmer.
Haskell has a very nice software transactional memory library, which makes a lot of otherwise-difficult concurrency problems much easier. It's statically safe, too, unlike similar libraries for imperative/OO languages.
Certain other language features are very nice. Monads are also extremely powerful once you wrap your head around them, and the type-class system and standard libraries make a lot of math programming problems much easier.
The language also has downsides. The laziness makes it possible to build up an arbitrarily long chain of suspended computations, which amounts to a hidden memory leak. Laziness also complicates the semantics for "unchecked" exceptions, most notably division by zero. The combination of laziness and purity can make the language very difficult to debug and optimize. While the compiler has very powerful optimization capabilities, sometimes code needs to be just so to use them (like flagging things "const" or "restrict" in C), and this can make it hard to write clean code that runs fast.
The other problem is that most programs need some amount of imperative code somewhere to do the I/O. This code has a tendency to be verbose, nasty and slow in Haskell.
There are also some problems that would be relatively easy to solve in a very nice way within the semantics of the language (give or take), but are not solved well in the standard libraries. These include exception handling, global mutable state, strings and regular expressions, certain I/O operations, arrays and references. It would be very nice if the ST and IO monads were unified, and if references and arrays had nice syntax; this would reduce the ugliness needed to write those occasional bits of imperative code.
I hereby place the above post in the public domain.
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.
1988 just called - it wants its reputation back.
Hackage is well known to haskell programmers. It is linked to directly from the front page of haskell.org, it is mentioned frequently on the haskell-cafe mailing list, and that's where hundreds of haskell projects are hosted. If you're an average passer-by and not an active haskell developer, it's not necessarily going to jump out and say "boo!", but it isn't hiding under a rock, either.
Note: hackage is not the standard libraries. Those are documented elsewhere.
I've seen the Fibonacci sequence used to show worst case input scenario in at least one algorithm.
We depend on normal users for that around here.
We get supposedly clean address data that's got pipe characters in it. No lie. About ten years ago we had a Sun system running software we bought from Xerox, and we fed it a normal data file from a large hospital, and it deleted its own /var partition. The Xerox guy said "it's not our fault, you shouldn't have dozens of metacharacters in the data" and we said "dude... you must really suck at programming. Of course the data's filthy, this isn't a college lab here."
When I worked in engineering, we used to test stuff by running the output of an AM radio tuned to static through a A/D converter.
.... You get Hell, Hell I tell you.
I regret that I only have one mod point to give per post.
Um, are Python generators any easier to understand than lazy evaluation to your "your average still-wet-behind-the-ears programmer"? The only way I can imagine this being so is that your programmer already did the hard work to learn C++ or Python, but didn't do any such work for Haskell--which begs the question, frankly.
Python generators ain't easy stuff. They're completely out of left field with regards to the rest of the language's stack-based flow control. How is the concept of reentering a local execution context that you exited before any simpler than lazy evaluation?
Are you adequate?
They did mention F# in the article - hadn't heard of it before... I'll have to check it out.
Bow-ties are cool.
Have things changed since Gabriel pointed out that Worse is Better?
I love Haskell -- maybe the most elegant language I've seen and my favorite underdog. But you've just pointed out the problem. All of the big efforts in the Haskell community are oriented around developer tools!
Compilers, source control, tools for other languages, build systems... and of course fancy libraries using advanced GHC extensions that are barely more understood than theory... all wonderfully powerful in case somebody... somewhere... wants to use them.
(A crappy 3D shooter that doesn't hold a candle to dozens of mainstream games each year doesn't count, I'm afraid.)
It sucks because programming is 99% about "side effects" than mathematical formulas.
Please note the use of quotes for 'side effects'. They are called 'side effects', although they are the most interesting part of programming. It's the part that things happen inside a computer that change the world.
Haskell makes it really difficult to write useful code (where useful means 'with side effects').
They may show you how to create 'infinite' number sequences and process them.
Cool. Ask them to make a Model-View-Controller application in Haskell, where the model is a tree of nodes modified by user actions. Trivial in imperative languages, hard as hell in Haskell: you have to use the a special monad, mix the useful code with visitation to the tree nodes, because the only way to modify tree node links in Haskell is via local arguments that 'pretend' to be the tree's nodes...