Fp13 Assignment1

(C) Ralf Lämmel, University of Koblenz Landau

# Assignment options

## Subtraction for natural numbers

Let's assume natural numbers are represented like this:

``````data Nat = Zero | Succ Nat
deriving (Show)```
```

Define a function for subtracting natural numbers. Please demonstrate that the natural numbers are not closed under subtraction.

## Special property of list elements

Define a function sameint which tests whether all ints in a list are the same.

This is the type of the function:

````sameint :: [Int] -> Bool`
```

Here is how the function behaves:

``````> sameint [1,2]
False
> sameint [1,1,1]
True```
```

## A stack with an error element

Let's assume stacks are represented like this:

``````data Stack = Empty | Push Int Stack | Error
deriving (Show)```
```

Define the pop operation such that Error is used when the pop operation is applied to the empty stack, thereby making this operation total. How would you make the top operation total?

page revision: 1, last edited: 02 Apr 2013 18:38