Walking Distance
type dir = N | S | E | W
Implement the function
val dist : dir list -> float
so that dist dirs, given a list of directions dirs, computes the
\(\ell_2\) distance (i.e., "as the crow flies") between the starting
point and ending point of the path given by dirs. Note that it
doesn't matter where you start, the distance between the starting and
ending points will always be the same.
Examples
let is_close f1 f2 = Float.abs (f1 -.f2) < 10. ** (-15.)
let _ = assert (is_close (dist [N; N; S; E]) (sqrt 2.))