Archive for July, 2011

Hard Time Learning Haskell?

July 13, 2011

Last week Ryan asked this excellent question:

For every single other programming language I’ve learned in the past, I was able to make useful, working programs in at most a week after learning about the language. But not for Haskell. Yes I understand what types and type classes are, how to create my own functions and I have a decent grasp of the syntax, but I’m just not sure where to begin. When I want to make something useful, I have to stick everything into a “do” statement and then afterwards I just get stuck and don’t know how to proceed.

How would you guys recommend I solve this problem?

Of course Haskell follows in a radical tradition of establishing platonic functiontional/applicative/declarative core language free of grubby earthly concerns. The machinery provided by the core is then used to build the I/O.

Note that tools like GHC aren’t built in this way but have been planned, constructed and refined with the concerns of real-world applications. But this all takes place within the functional framework established by the core. (A prime motivation for this radical dicipline [if 1980s research grant applications are any guide] was the opportunities it would open up for exploiting massively parallel architectures — see, for example this talk by Simon Peyton Jones).

So most Haskell introductory texts wait until about the penultimate chapter before tackling I/O. But this does not at all jibe with the conventional evolution in learning a programming language where you expect to be writing ‘real programmes’ within a week.

My advice therefore is to kick back, spend some time on (e.g.) the first 17 chapters of Thompson’s book. You should definitely be expecting to spend (at least) the first week interacting with your scripts though the ghci evaluation prompt.

But can Haskell I/O be tackeld in week 2?

Just Haskell

July 10, 2011

Welcome to Just Haskell, a blog on the Haskell programming language.

What’s in a Name?

The name of the blog is a play on several things, but now would be an appropriate time to talk about beginnings and the beginnings of the Haskell language. The most important innovation of Haskell is its monadic I/O system. It wasn’t there at the start, but invented and added subsequently (in 1996) after Philip Wadler’s early nineties papers sparked the revolution. In his ’92 POPL paper Wadler mentioned (among others) Michael Spivey’s work on monadic exception handling with the Maybe type as an important precursor. Thus I justify the cheeky name of my blog — a tribute to innovation that Haskell and its tools were intended to encourage.

While we are on beginnings I would like to acknowledge two personal pre-Haskell influences. I came to Haskell and functional programming through the Miranda programming language, David Turner’s 1986 Sigplan notices paper being especially influential. This compactness and elegance was on a different plane from anything else I had encountered. I still like to write out the definition of the prime numbers from time to time (in Haskell of course):

primes :: [Integer]
primes = sieve [2..]
      where
        sieve (p:xs) = p : sieve [ x | x<-xs, x `mod` p /= 0 ]

This has got to be one for the book.

For me the key innovation of Monadic I/O was to apply type abstraction to the data structures (streams and continuations) in such a way that made functional programs performing I/O composable. Simon Thompson’s 1987 report Interactive functional programs: a method and a formal semantics was the first place I encountered this idea and why it was so important. When the Monads papers started emerging it seemed like a very good thing indeed.

Enough already. Time to blog.

Follow

Get every new post delivered to your Inbox.