Archive for the ‘haskell’ Category

Python talk for WYLUG, Ruby envy, Haskell Joy.

December 27th 2007

I am just getting a talk ready for WYLUG on python.

I sent Dave the following blurb:

Why I love Python:

A talk on the programming language Python, in 3 parts (feel free to
leave in the interludes if you have had enough)

Part 1: Past, Present, Future.
A bit of history and the design of the language, a look at all the
implementations available today, quick tour of built-in and commonly
used modules and future plans.

Part 2: Language overview
A quick tour of the language: builtin types, control structures, using
modules etc

Part 3: Recent Magic.
Some relatively recent changes that make programming Python even more
pleasurable.
Decorators, Generators, List comprehensions, Iterators, Functools and
anything else I can fit in.
Again a whirlwind tour, but you should be impressed and want to read
up on these some more

I have been revisiting some of the Python talks I have watched over the last few years for ideas and will update my ComSci page with links.

I stumbled across some excellent video from RubyConf, particularly the Rubinius one. Rubinius is a ruby VM partially written in Ruby, taking some lessons from Python and Smalltalk. Some of the stuff he bigs up (compiling to bytecode automatically comes to mind) Python has had for ages, but the self hosting aspect is cool (not as cool as PyPy though). Rubinius seems to be doing what Avi Bryant suggested here, learn from the Smalltalk guys and the papers from the Self team that Sun spun off and later bought back to do the hotspot VM for Java. Interesting times for dynamic languages, target the JVM, CLR, self host and generate code in other languages while always writing in the same fun language. I say Ruby envy only because I think the Ruby community does a better job of looking cool and exciting people than the Python one.

Now Haskell joy. After describing working through Yet Another Haskell Tutorial to the 2 friends doing it with me as “not an obviously pleasurable experience” I had a great moment on the train the other day looking at partial application.
(\y -> y*3)
is Haskell for the anonymous function that takes y and multiplies it by 3 (I wish I had LaTeX here to draw the lamda calculus). What I like is that you can also write that as
(*3)
While this example is trivial, what is happening is interesting. The compiler knows * is an infix operator that takes 2 arguments and that is has been supplied one and “partially applies” the function, making (*3) (a function that takes one argument). One more thing is changing prefix and infix operators around using ( _ ) and ` _ ` , for example:
3 * 5
(*) 3 5

map (*2) [1,2,3]
(*2) `map` [1,2,3]

I hope this second example is clear, map usually is a prefix function that takes a function and a list and returns a list with the result of applying the function to each element (the return value here would be [2,4,6]). This flexibility is neat and is starting to make Haskell a joy to hack in.

Merry Christmas,

Posted by tom under Ruby & Python & haskell | No Comments »

Faith, Evolution, and Programming Languages

November 28th 2007

I just watched Faith, Evolution, and Programming Languages, a Google EngEDU video. It was by Philip Wadler, a chap who I had never heard of but who has done loads of cool things. He designed Haskell’s Type Classes and Java’s Generics, and is currently working on a bridge between strongly typed and dynamically typed languages. The talk starts off with a brief, fascinating explanation of links (more properly isomorphisms) between logics and programming languages and makes the point that aliens may not create Java but certainly will create (discover?, I suppose it depends if you are a Platonist) the lambda calculus (calculi ?).

For about 20 mins towards the end I lost the plot and could not really follow his argument, but I will revisit it when I know a bit more. I am glad I hung on as the 10 minutes of discussion at the end were quite interesting and Links (the recent work he did not have time to show the slides for, a web framework with every tier written in the same language) seemed very interesting.

For more on the language/logic link, see here

Posted by tom under Java & ComSci & haskell | No Comments »

Why I am learning Haskell

November 27th 2007

I saw Simon Peyton-Jones talk on Software Transactional Memory at OSCON and was amazed at how neat it sounded. Taking some ideas from databases to remove some of the pain of multithreaded programming is a great idea. His point that a thread-safe Dequeue is a post-doc publishable result convinced me that something is wrong with the threading models in widespread use, while STM reduces it to an undergrad problem. The maping from the complexity of the problem domain to your code should be sane, if implementing a a simple structure like a dequeue using threads makes the code lots longer and requires a large amount of effort by someone with a doctorate, something is wrong. I love python, but multithreaded programs suffer (at least in the C implementation) because of the global interpretor lock (GIL). So I decided to learn Haskell.

There are (as far as I know) two ways of doing concurrency; shared state and message passing. STM is a neat syntax and smart compiler technology that ultimately uses shared state. See a Java or C# implementation here.

Erlang is becoming increasingly popular and big successes with high availability at Ericsson are compelling real world examples of its use. It uses message passing concurrency and is a nice (mostly) functional language. I am happy with the choice of Haskell though, the syntax seems neat (because of my maths background) and the functional purity enforces functional thinking more than (say) Common Lisp or OCaml. There was a great post today on Planet Haskell on concurrency options in Haskell and I am keen to explore them.

Maybe I will not hack in Haskell full time, but I think some of the ideas will go mainstream (already appearing in Linq and C# from Microsoft, who have bought in a lot of talented folk from the FP world ), but maybe I will.

It fits my mind well so far.

Posted by tom under ComSci & FP & haskell | No Comments »

Mind Bending Stuff

November 1st 2007

I am just getting my head around this (pdf) comment on the problem at the last ICFP Programming Contest , anyone who likes puzzles, compilers and reverse engineering should take a look, I am amazed by how rich this problem was. The ICFP do not specify what counts as “functional”, but OCaml and Haskell usually do very well in the contest. This year a C++ team won it and a perl team came second, after lots of teams abandoned their functional languages. The authors make the point that data structure design/choice is very important (which we all should know I suppose), they recommend Data.sequence in Haskel and I think it is similar to a Rope (sort of tree based string representation that makes concatenation a snip, wikipedia is weak on it but Ruby Quiz mentioned it a few weeks ago)

Posted by tom under ComSci & FP & OCaml & haskell | No Comments »