
Hi, I will be a TA on a comparative PL course and I'm looking for small examples (ammunition) which motivate the use of Haskell and functional programming generally. The course is for 1st year Software Engineers, none of whom are likely to have used a functional language. They will all have experience programming Java and a little C++, with a few of them knowing Python, Ruby, PHP etc etc too. If anyone has code snippets which are the equivalent of an elevator pitch for FP, I would be very grateful to see them. What I want are some small concrete examples of idioms which are natural and powerful in Haskell but difficult or impossible in, say, Java. So I can produce examples of some of the things that make FP powerful, elegant, expressive etc: higher order functions, polymorphism, composition (ask them to write (.) in Java :-)), partial application and so on. I will point any interested souls to Hughes' great paper [1]. But I have little time and it might be hard to put across why they would want to do these things in the first place. I was looking for something that speaks directly to the kind of problems they face in languages like Java... Types are a good example because Java programmers generally already appreciate the help they get from compiler messages etc, so you can sell a more flexible, enhanced form of this. Purity might appeal to anyone who has longed to be able to reason about nastily complex code with a lot of shared state. Laziness, streams? Hard to do in Java (I presume) but also quite hard to sell the need. The existence of an O'Reilly book will help, especially one that can be sampled online, so I'll point them at RWH for extended concrete examples. They will need to be already sold before they will bother with that though. Thanks, Jim [1] http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html

There was a thread about that:
http://www.haskell.org/pipermail/haskell-cafe/2007-September/ 031402.html
Am 20.01.2009 um 11:07 schrieb Jim Burton:
Hi, I will be a TA on a comparative PL course and I'm looking for small examples (ammunition) which motivate the use of Haskell and functional programming generally. The course is for 1st year Software Engineers, none of whom are likely to have used a functional language. They will all have experience programming Java and a little C++, with a few of them knowing Python, Ruby, PHP etc etc too.
If anyone has code snippets which are the equivalent of an elevator pitch for FP, I would be very grateful to see them. What I want are some small concrete examples of idioms which are natural and powerful in Haskell but difficult or impossible in, say, Java.
So I can produce examples of some of the things that make FP powerful, elegant, expressive etc: higher order functions, polymorphism, composition (ask them to write (.) in Java :-)), partial application and so on. I will point any interested souls to Hughes' great paper [1]. But I have little time and it might be hard to put across why they would want to do these things in the first place. I was looking for something that speaks directly to the kind of problems they face in languages like Java...
Types are a good example because Java programmers generally already appreciate the help they get from compiler messages etc, so you can sell a more flexible, enhanced form of this. Purity might appeal to anyone who has longed to be able to reason about nastily complex code with a lot of shared state. Laziness, streams? Hard to do in Java (I presume) but also quite hard to sell the need.
The existence of an O'Reilly book will help, especially one that can be sampled online, so I'll point them at RWH for extended concrete examples. They will need to be already sold before they will bother with that though.
Thanks,
Jim
[1] http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Adrian Neumann wrote:
There was a thread about that:
http://www.haskell.org/pipermail/haskell-cafe/2007-September/ 031402.html
Thanks! I didn't literally mean "elevator pitch" and if I knew that thread existed would have phrased my post differently, because a list of the things that are cool about Haskell will not impress them. What I want and am finding it hard to create are examples where FP shines and, for the same problem, imperative languages look like more work. Many will think of programming solely in terms of developing websites, GUIs, database access, so I will demonstrate how strongly-typed database access can help them. Jim
Am 20.01.2009 um 11:07 schrieb Jim Burton:
Hi, I will be a TA on a comparative PL course and I'm looking for small examples (ammunition) which motivate the use of Haskell and functional programming generally. The course is for 1st year Software Engineers, none of whom are likely to have used a functional language. They will all have experience programming Java and a little C++, with a few of them knowing Python, Ruby, PHP etc etc too.
If anyone has code snippets which are the equivalent of an elevator pitch for FP, I would be very grateful to see them. What I want are some small concrete examples of idioms which are natural and powerful in Haskell but difficult or impossible in, say, Java.
So I can produce examples of some of the things that make FP powerful, elegant, expressive etc: higher order functions, polymorphism, composition (ask them to write (.) in Java :-)), partial application and so on. I will point any interested souls to Hughes' great paper [1]. But I have little time and it might be hard to put across why they would want to do these things in the first place. I was looking for something that speaks directly to the kind of problems they face in languages like Java...
Types are a good example because Java programmers generally already appreciate the help they get from compiler messages etc, so you can sell a more flexible, enhanced form of this. Purity might appeal to anyone who has longed to be able to reason about nastily complex code with a lot of shared state. Laziness, streams? Hard to do in Java (I presume) but also quite hard to sell the need.
The existence of an O'Reilly book will help, especially one that can be sampled online, so I'll point them at RWH for extended concrete examples. They will need to be already sold before they will bother with that though.
Thanks,
Jim
[1] http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Jim Burton

Jim Burton wrote:
Adrian Neumann wrote:
There was a thread about that:
http://www.haskell.org/pipermail/haskell-cafe/2007-September/ 031402.html
Thanks! I didn't literally mean "elevator pitch" and if I knew that thread existed would have phrased my post differently, because a list of the things that are cool about Haskell will not impress them. What I want and am finding it hard to create are examples where FP shines and, for the same problem, imperative languages look like more work.
Parallelism! Something based on dons' blog http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking-4core will be a good start. Many will think of
programming solely in terms of developing websites, GUIs, database access, so I will demonstrate how strongly-typed database access can help them.
Jim
[...]
-- View this message in context: http://www.nabble.com/Elevator-pitch-for-functional-programming-tp21560192p2... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

One of the coolest things about Haskell is the ability to refer to values not yet calculated, without having to work out the timing yourself. You want Fibonacci numbers? Prelude> let z = zipWith (+) (0:1:z) (0:z) in take 10 z [0,1,1,2,3,5,8,13,21,34] Try doing that in one line of C++. See also e.g. http://sigfpe.blogspot.com/2006/12/tying-knots-generically.html Dan Jim Burton wrote:
Jim Burton wrote:
There was a thread about that:
http://www.haskell.org/pipermail/haskell-cafe/2007-September/ 031402.html Thanks! I didn't literally mean "elevator pitch" and if I knew that thread existed would have phrased my post differently, because a list of the
Adrian Neumann wrote: things that are cool about Haskell will not impress them. What I want and am finding it hard to create are examples where FP shines and, for the same problem, imperative languages look like more work.
Parallelism! Something based on dons' blog http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking-4core will be a good start.
Many will think of
programming solely in terms of developing websites, GUIs, database access, so I will demonstrate how strongly-typed database access can help them.
Jim
[...]

At Tue, 20 Jan 2009 12:25:00 -0800, Dan Weston wrote:
Hi Dan,
One of the coolest things about Haskell is the ability to refer to values not yet calculated, without having to work out the timing yourself.
You want Fibonacci numbers?
Well, I might but they definitely do not :-) We are talking about some maths-averse people and you would not have got to the final syllable of 'fibonacci' before all hope was lost. But I am sure there are plenty of examples that rely on laziness which will communicate. I am sure I read a blog post or something on c.l.f/c.l.h recently about lazily sorting a million numbers but can't find it. Jim
Prelude> let z = zipWith (+) (0:1:z) (0:z) in take 10 z [0,1,1,2,3,5,8,13,21,34]
Try doing that in one line of C++.
See also e.g.
http://sigfpe.blogspot.com/2006/12/tying-knots-generically.html
Dan
Jim Burton wrote:
Jim Burton wrote:
There was a thread about that:
http://www.haskell.org/pipermail/haskell-cafe/2007-September/ 031402.html Thanks! I didn't literally mean "elevator pitch" and if I knew that thread existed would have phrased my post differently, because a list of the
Adrian Neumann wrote: things that are cool about Haskell will not impress them. What I want and am finding it hard to create are examples where FP shines and, for the same problem, imperative languages look like more work.
Parallelism! Something based on dons' blog http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking-4core will be a good start.
Many will think of
programming solely in terms of developing websites, GUIs, database access, so I will demonstrate how strongly-typed database access can help them.
Jim
[...]

Jim Burton schrieb:
Well, I might but they definitely do not :-) We are talking about some maths-averse people and you would not have got to the final syllable of 'fibonacci' before all hope was lost. But I am sure there are plenty of examples that rely on laziness which will communicate. I am sure I read a blog post or something on c.l.f/c.l.h recently about lazily sorting a million numbers but can't find it.
Maybe they are interested in finding all equal files in a set of files. This can be done in an elegant way by sorting the files with respect to their content. Practical enough? http://hackage.haskell.org/cgi-bin/hackage-scripts/package/equal-files

At Tue, 20 Jan 2009 22:08:55 +0100, Henning Thielemann wrote:
Jim Burton schrieb:
Well, I might but they definitely do not :-) We are talking about some maths-averse people and you would not have got to the final syllable of 'fibonacci' before all hope was lost. But I am sure there are plenty of examples that rely on laziness which will communicate. I am sure I read a blog post or something on c.l.f/c.l.h recently about lazily sorting a million numbers but can't find it.
Maybe they are interested in finding all equal files in a set of files. This can be done in an elegant way by sorting the files with respect to their content. Practical enough?
Indeed, thanks! Jim
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/equal-files

Jim Burton wrote:
Parallelism! Something based on dons' blog http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking-4core will be a good start.
+3 Ever tried to do anything like this in Java? Even Smalltalk makes it relatively hard compared to Haskell's parallelism primitives. (I do *mean* parallelism, not concurrency - although Haskell does that pretty damned impressively too...)

I recommend checking out Don Syme's slides from CUFP 2008.
http://cufp.galois.com/2008/slides/
This isn't Haskell directly, it's F#, but it fits the "functional
programming generally", and the two languages have, relative to the
universe of programming languages, more in common than they do
different.
There's a lot of "would you rather write this?" with a giant chunk of
C#, followed by "or this?" with a few readable lines of F#.
-- ryan
On Tue, Jan 20, 2009 at 2:07 AM, Jim Burton
Hi, I will be a TA on a comparative PL course and I'm looking for small examples (ammunition) which motivate the use of Haskell and functional programming generally. The course is for 1st year Software Engineers, none of whom are likely to have used a functional language. They will all have experience programming Java and a little C++, with a few of them knowing Python, Ruby, PHP etc etc too.
If anyone has code snippets which are the equivalent of an elevator pitch for FP, I would be very grateful to see them. What I want are some small concrete examples of idioms which are natural and powerful in Haskell but difficult or impossible in, say, Java.
So I can produce examples of some of the things that make FP powerful, elegant, expressive etc: higher order functions, polymorphism, composition (ask them to write (.) in Java :-)), partial application and so on. I will point any interested souls to Hughes' great paper [1]. But I have little time and it might be hard to put across why they would want to do these things in the first place. I was looking for something that speaks directly to the kind of problems they face in languages like Java...
Types are a good example because Java programmers generally already appreciate the help they get from compiler messages etc, so you can sell a more flexible, enhanced form of this. Purity might appeal to anyone who has longed to be able to reason about nastily complex code with a lot of shared state. Laziness, streams? Hard to do in Java (I presume) but also quite hard to sell the need.
The existence of an O'Reilly book will help, especially one that can be sampled online, so I'll point them at RWH for extended concrete examples. They will need to be already sold before they will bother with that though.
Thanks,
Jim
[1] http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

At Tue, 20 Jan 2009 14:17:10 -0800, Ryan Ingram wrote:
I recommend checking out Don Syme's slides from CUFP 2008.
http://cufp.galois.com/2008/slides/
This isn't Haskell directly, it's F#, but it fits the "functional programming generally", and the two languages have, relative to the universe of programming languages, more in common than they do different.
There's a lot of "would you rather write this?" with a giant chunk of C#, followed by "or this?" with a few readable lines of F#.
Hi, those slides look useful and inspiring. Thanks a lot. Jim
-- ryan
On Tue, Jan 20, 2009 at 2:07 AM, Jim Burton
wrote: Hi, I will be a TA on a comparative PL course and I'm looking for small examples (ammunition) which motivate the use of Haskell and functional programming generally. The course is for 1st year Software Engineers, none of whom are likely to have used a functional language. They will all have experience programming Java and a little C++, with a few of them knowing Python, Ruby, PHP etc etc too.
If anyone has code snippets which are the equivalent of an elevator pitch for FP, I would be very grateful to see them. What I want are some small concrete examples of idioms which are natural and powerful in Haskell but difficult or impossible in, say, Java.
So I can produce examples of some of the things that make FP powerful, elegant, expressive etc: higher order functions, polymorphism, composition (ask them to write (.) in Java :-)), partial application and so on. I will point any interested souls to Hughes' great paper [1]. But I have little time and it might be hard to put across why they would want to do these things in the first place. I was looking for something that speaks directly to the kind of problems they face in languages like Java...
Types are a good example because Java programmers generally already appreciate the help they get from compiler messages etc, so you can sell a more flexible, enhanced form of this. Purity might appeal to anyone who has longed to be able to reason about nastily complex code with a lot of shared state. Laziness, streams? Hard to do in Java (I presume) but also quite hard to sell the need.
The existence of an O'Reilly book will help, especially one that can be sampled online, so I'll point them at RWH for extended concrete examples. They will need to be already sold before they will bother with that though.
Thanks,
Jim
[1] http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Jim Burton wrote:
Hi, I will be a TA on a comparative PL course and I'm looking for small examples (ammunition) which motivate the use of Haskell and functional programming generally. The course is for 1st year Software Engineers, none of whom are likely to have used a functional language. They will all have experience programming Java and a little C++, with a few of them knowing Python, Ruby, PHP etc etc too.
It's getting to be something of an old hat these days, but one of the most powerful selling points I've seen for purity (and strong types) is QuickCheck (and SmallCheck, LazySmallCheck,...). This entire paradigm of testing makes writing tests trivial and can only work right for pure functions. I don't know if your students are just students or if they have some real software engineering experience, but anyone who's hacked on Perl, Python, Ruby, Java, or C++ enough to earn the title would be immensely impressed by how purity eases debugging. -- Live well, ~wren

On Jan 20, 2009, at 7:35 PM, wren ng thornton wrote:
Jim Burton wrote:
Hi, I will be a TA on a comparative PL course and I'm looking for small examples (ammunition) which motivate the use of Haskell and functional programming generally. The course is for 1st year Software Engineers, none of whom are likely to have used a functional language. They will all have experience programming Java and a little C++, with a few of them knowing Python, Ruby, PHP etc etc too.
It's getting to be something of an old hat these days, but one of the most powerful selling points I've seen for purity (and strong types) is QuickCheck (and SmallCheck, LazySmallCheck,...). This entire paradigm of testing makes writing tests trivial and can only work right for pure functions.
I don't know if your students are just students or if they have some real software engineering experience, but anyone who's hacked on Perl, Python, Ruby, Java, or C++ enough to earn the title would be immensely impressed by how purity eases debugging.
I second this! For all of the wonderful benefits Haskell has, this is the one I miss most when programming in another language. For an example of how hard it is to accomplish something like this in Java, check out JCrasher: http://ranger.uta.edu/~csallner/jcrasher/. Much less powerful, and much more work. Aaron
participants (8)
-
Aaron Tomb
-
Adrian Neumann
-
Andrew Coppin
-
Dan Weston
-
Henning Thielemann
-
Jim Burton
-
Ryan Ingram
-
wren ng thornton