(i) Code a function follows: ('a * 'a -> bool) -> 'a list -> bool that returns true if and
only if every pair of consecutive elements in the given list is in the given relation. (Notice that, if
the given list is of length less than 2, this is trivially the case.)
1
- follows op<> [1,3,2,8,3];
val it = true;
- follows op<> [1,3,2,2,3];
val it = false;
- follows op<> [1,2,17,235];
val it = true;
- follows op<> [1,17,2,235];
val it = false;
(ii) Use follows to code a function validCompr : ('a * int) list -> bool that checks if the
given list of value and integer pairs is a valid compression, i.e., that, (a) in each such pair, the
number component is non-0 (and also non-negative), and (b) in each two consecutive such pairs,
the value components are different.
- validCompr [(17, 3), (42, 5), (1011, 2)];
val it = true
- validCompr [(17, 3), (2018, 0), (42, 5), (1011, 2)];
val it = false
- validCompr [(17, 3), (42, 2), (42, 3), (1011, 2)];
val it = false