We implemented the following type synonym for a `Integer`-bound.

type Bounds = (Integer,Integer)

1) Implement a function `moveWithinBounds` that yields a coordinate based on a given bound, direction and coordinate. The new coordinate changes by one unit (that is, plus 1 or minus 1) from the given coordinate in the y-component (or x-component) with respect to the given direction. If the resulting change in that component does not adhere with the given bounds, the new coordinate is identical to the given one.

2) Evaluate the following expression step-by-step, specifying the demanded argument as well as the applied rule as done in the lecture, for the constant function `boolEx4`.

```

boolEx4 = False && (True || True)

```

boolEx4

^^^^^^^

= { definition of `boolEx4`}

False && (True || True)

^^^^^^^^^^^^^^^^^^^^^^^

= { definition for `(&&)`: second rule without binding any variables }

False

3) Consider the following `Bool`ean expressions in Haskell. Note that the operator `(==>)` is defined in the lecture notes.

a) True || False && True ==> not False

b) False ==> True ==> True

c) False && True ==> True || False ==> True || not False

A) Give the fully parenthesised versions of the following `Bool`ean expressions in Haskell with respect to their precedences.

4) Given the following definition of an implication on Boolean values as well as a non-terminating constant `boolLoop`

```

impl :: Bool -> Bool -> Bool

impl True True = True

impl True False = False

impl False _ = True

boolLoop :: Bool

boolLoop = boolLoop

```

which of the following expression will terminate, which of them won't? Try to explain why this is the case.

a) impl (impl (False && True) False) boolLoop

b) boolLoop ==> True

c) False ==> boolLoop

a) won't terminate: first parameter evaluates to `True` and therefore the second argument needs to be evaluated

b) won't terminate: first argument needs to be evaluated

c) terminates: `imp` does not evaluate its second argument if the first argument is `False`

Can you give an alternative implementation (or choose one from the lecture) that will terminate for one of the example that won't terminate for `impl`?

```

impl :: Bool -> Bool -> Bool

impl True x = x

impl False_ = True

```

Using this version of the implementation example a) terminates.

```

impl :: Bool -> Bool -> Bool

impl _ True = True

impl x False = not x

```

With this version of `impl`, example b) terminates.

<<<------------- Exercises corresponding to lecture on 9/12/19 ------------->>>

First we define a data type for `Token`s as follows.

>dataTokenwhere

>Blank::Token

>Block::Token

Consider now the following data type that is a list-like structure like we have seen for `CoordMap` but for `Token`.

>dataRowwhere

>EmptyR::Row

>ARow::Token->Row->Row

5) Implement a function `prettyRow` that prints each `Token` of the row seperated by one whitespace.