Programming in Haskell

After last Sunday’s start of a Programmers’ Salon, I have not thought more about Olav’s glowing words on how the Haskell programming language does interactive input.

The problem can be formulated thusly: Haskell is a side-effect-less language, a purely functional language. How can it take interactive input?

We wallow in side-effects in the imperative languages, it’s what we do.

The answer lies in monads. They are “used to express sequential composition”. Sequence! Haskell has none! I was flabbergasted when the implications hit me. And they keep hitting me. (Reading a Monads tutorial for mortals could help, but relating this feeling of being so close to so much power seems like a good idea right now.)

The book Programming in Haskell has a few rather informative and thought-provoking Powerpoint slides up.

I got a lot of mileage out of Tour of the Haskell syntax, too. (Via the tag “Haskell” on

The code that looks like this might scare you off, but the Ruby crowd gets a leg up on the rest of you: this reeks of Ruby’s blocks.

[ (x, y) | x < - [1..3], y <- "abc" ]

The tuple (x,y) is going to be filled with successive integers and characters. The end result is a list of tuples like this:


To do that thing, Ruby uses the class SyncEnumerator of its standard library Generator to increment two variables at a time. See its doc, beautifully generated by RDoc.

> require ‘generator’

> s =[1,2,3], [‘a’, ‘b’, ‘c’])

> # Yields [1, ‘a’], [2, ‘b’], and [3,’c’]
> s.each { |row| puts row.join(‘, ‘) }

I can see now that Ruby is always more legible. Its pragmatism stands out more when I look at “pure” languages. Emotionally, I like it like that. But, really, there is power in these super-abstract modes of thought.

And where are the Ruby limericks?

Published by Olle Jonsson

Human. Wears glasses and often a smile.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.