... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2008-01-31

Implications of Non-Strict Functions

Here is a great little Haskell snippet that will wrench you out of imperative thinking:

notimperative x = (a,b,c,d) where
  (a,b) = incr x c
  (c,d) = incr d a
  incr i j = (i+1,j+1)

The result of evaluating notimperative 1 is (2,5,4,3).

A pithier, but more obvious, version is:

notimperative2 x = (a,b) where
  (a,b) = (b+1,x)

Blog Archive