8.4.2 Type inconsistencies
I was stumped on writing this function,
let calculateRemainingPetrol(currentPetrol:int, distance:int) : int =
so I looked at the “solution”, which is clearly in error:
/// Calculates remaining petrol after driving
let calculateRemainingPetrol(currentPetrol, distance) =
let remainingPetrol = currentPetrol  distance // what?
if remainingPetrol >= 0 then remainingPetrol
else failwith "Ooops! You ran out of petrol!"
The “units” of currentPetrol and distance are both ints, BUT currentPetrol is a measure of volume, whereas distance is a measure of length. Thus
currentPetrol – distance
is nonsense.
