There's going to be a functional programming meeting in San Francisco on September 13. I want to go.
An interesting thing about Haskell for me is that it hasn't been very clear to me why I'm so interested in it. This is revealing from a post by Bryan O'Sullivan:
We puzzled with Simon over the mystery of this recent buzz around functional programming languages. The best stab I could make at a guess was that languages like Python and Ruby have introduced a generation of programmers to the idea that their code can be expressive and concise. News is percolating out that Haskell offers comparable or better facilities for abstraction and brevity, but with the additional benefits of safety, native code performance, and multicore scalability.
The quote comes from a post Bryan O'Sullivan wrote about Simon Peyton Jones' Haskell sessions at OSCON: A brief Haskell-at-OSCON trip report
- Barbara Haven
- Dave Fletcher
- Alice Marshall
- Phil Windley
- Doug Bromley
- Chris Minnick
- Wayne Hall
- Damien Katz
- Dave Winer
- Don Stewart (Hacking Haskell)
- Lennart Augustsson
- Guido van Rossum
- Neil Mitchell
- Paul Graham
- John Goerzen
- Philip Wadler
- Learning Lisp
- Tim Bray
- Bryan O'Sullivan
- Michael Harrison
- Slava Akhmechet (defmacro)
- Lambda the Ultimate
- Paul Hepworth
- Peter Seibel
Guido van Rossum, the creator of the Python programming language, recently blogged about a python that ate a sheep and then got stuck in an electrical fence. Good pictures.
All functions in Haskell take only one argument. So how do you define functions that take multiple arguments? You don't.
Instead Haskell has currying.
As addition usually takes two arguments (two numbers to add) let's use it as a problem to solve with currying.
A way to think of currying is instead of using one function that takes multiple arguments, use multiple functions that each solve a single argument. Since our version of addition takes two arguments, we are going to have two functions, each taking a single argument.
Here is the currying addition function:
add x = \y -> x + y
There are some interesting things going on here in this code. The whole line, "add x = \y -> x + y", is one function definition called add, but there is another function defined in this line but it doesn't have a name. This part, "\y -> x + y", is a function definition. It could be called a function without a name or an anonymous function or a lambda function. It says that there is one argument (y) and it returns the value from x + y. y is the value from the argument, and the value x comes from outside the function definition, from the x argument for add. Functions that have values defined outside their definition are called closures, so the anonymous function here is a closure.
So what does this line of code do? Let's run it!
add 5 6
Okay, so the first argument is 5. Let's go through this execution in slow motion. Let's put 5 everywhere x is in the function definition:
add 5 = \y -> 5 + y
Okay, since there is nothing left to do here since nothing references what y is so we can't evaluate anything more, we return the value of the function add. The only thing here is the function definition "\y -> 5 + y" so we return that function as the return value of the function add. Let's replace the add function with its return value:
add 5 6
-- we return add 5 and we get:
(\y -> 5 + y) 6
Here we get the anoymous function with the value 6 being passed into it:
(\y -> 5 + y) 6
-- results in:
(\6 -> 5 + 6)
-- which results in:
(5 + 6)
The answer is 11!
Y Combinator is changing news.ycombinator.com into Hacker News. It is going to focus on things of interest to hackers, and they are going to use a system and human editors to keep it good. Before the news site just focused on startup news.
This is great. Here's Paul Graham's announcement.
For awhile last week the book Lisp in Small Pieces was the best selling book on the Canada Amazon.com website, out selling Harry Potter. Currently Lisp in Small Pieces is number 3. The book usually sells at $50—$94.40, but last week on the Canada Amazon.com website, Amazon was selling it for $3.95 according to various posts on the web, like this one.
Tonight I asked people from IRC #haskell if haskell was good for writing compilers and interpreters, as I had gotten that idea. They told me this was very much true.
Here's some items on the web about compilers and interpreters written in Haskell:
- Pugs, one of the main implementations of Perl 6, is written in Haskell.
- Here's a tutorial called Write Yourself a Scheme in 48 Hours, about writing Scheme in Haskell.
- Articled entitled: Writing A Lisp Interpreter In Haskell.
- Here's a list of more compilers and interpreters. The list includes Haskell compilers written in Haskell.
I've been coming across a lot of interesting programming items on the web recently. Here are some of them:
More in my del.icio.us account.