I was playing around with the Peano numerals in Haskell (as I often do), because I remember briefly reading about a generalisation of exponentiation in a paper once when I didn't have time to read it. I decided I'd quickly look at it again now that I was in a mood to procrastinate.

>data Nat = Z | S Nat deriving Show This data type is usually identified with the peano numerals. In fact as we will see, in haskell it isn't quite the natural numbers. We take Z to mean 0 and take (Sn Z) or (S (S (S ... Z))) n times, to mean n. It's basically a unary number system where the length of the string gives us the number.

It is pretty straightforward to write the basic arithmetic operations on the peano numerals.

> add x Z = x > add x (S y)= S (add x y)> mult x Z = Z > mult x (S y)= add x (mult x y)> expt x Z =(S Z)> expt x (S y)= mult x (expt x y)Here we can see an extension of this series fairly easily. The only real question we might have is what to do …

>data Nat = Z | S Nat deriving Show This data type is usually identified with the peano numerals. In fact as we will see, in haskell it isn't quite the natural numbers. We take Z to mean 0 and take (Sn Z) or (S (S (S ... Z))) n times, to mean n. It's basically a unary number system where the length of the string gives us the number.

It is pretty straightforward to write the basic arithmetic operations on the peano numerals.

> add x Z = x > add x (S y)= S (add x y)> mult x Z = Z > mult x (S y)= add x (mult x y)> expt x Z =(S Z)> expt x (S y)= mult x (expt x y)Here we can see an extension of this series fairly easily. The only real question we might have is what to do …