Good stuff for programming geeks
[ start | index | login or register ]
start > Talk - Haskell for Perl Hackers

Talk - Haskell for Perl Hackers

Created by tmoertel. Last edited by tmoertel 775 days ago. Viewed 5348 times. #11
[diff] [history] [edit] [rdf]
labels
Category:Haskell
attachments

I gave this talk to the >>Pittsburgh Perl Mongers on 2004-02-11.

Slides. You can download the slides in PDF format: pgh-pm-talk-haskell.pdf

>>Haskell is a remarkable programming language. It combines some of the best thinking in modern computer-language research with good taste and pragmatism. The result is a powerful tool that is rigorous yet fun, expressive and efficient, clean and concise. I love it.

I also love Perl. No other language gives programmers such a powerful collection of tools (some dangerous) and says, Here you go. I trust that you know what to do with these things. Now, I'll step out of the way while you get your work done.

Thus it's probably no surprise to learn that I have been saying nice things about Haskell to my friends at Perl Mongers meetings. Being open-minded folks, they (finally!) asked me to give a short talk on Haskell. This is that talk.

As far a depth goes, the talk only scratches the surface. I avoided some of Haskell's most powerful features like monads, functional dependencies, multi-parameter type classes, combinators, and list comprehensions because I didn't want to introduce too many new concepts. While these concepts are deeply cool, the depth of their coolness becomes meaningful only after repeated use, something that's not practical for a short talk. (And I should note that I ran about an hour long, as it was.)

What I did talk about were lists, higher-order functions, laziness, pattern matching, and (briefly) Haskell's type system. As examples, I introduced zip, flip, and map; wrote an even-odd sort to show pattern matching, pattern guards, and where at work; wrote a run-length encoder and decoder; and finally used >>QuickCheck to test the encoder and decoder.

That was the talk. There were a few questions afterward, but not as many as I had hoped for. I got the feeling that I had overstuffed the talk and as a result didn't leave a lasting impression. Oh well. Live and learn, right?

On the even-odd sort

After the talk, I was thinking about the even-odd sort that I used as an example. I realized that you can write the partitioning step more concisely by numbering the elements and then testing the numbers for even- or oddness:

evenOddSort []  = []
evenOddSort [x] = [x]
evenOddSort xs  = merge (evenOddSort (map snd evens))
                        (evenOddSort (map snd odds))
    where
    (evens, odds) = partition (even . fst) (zip [0..] xs)

merge (x:xs) (y:ys) | x <= y = x : merge xs (y:ys) | otherwise = y : merge (x:xs) ys merge xs ys = xs ++ ys

However, compared to the original from the slides, this version is less efficient and – more to the point – doesn't make as good of an example for pattern matching.

Still, with Haskell there's more than one way to do it. ;-)

no comments | post comment
community.moertel.com | Copyright © 2003–07 Moertel Consulting