Consider the function fun gl hdl tll handle hd gt nil


Exceptions

ML has functions hd and t1 to return the head (or ?rst element) and tail (or remaining elements) of a list. These both raise an exception Empty if the list is empty. Suppose that we rede?ne these functions without changing their behavior on nonempty lists, so that hd raises exception Hd and tl raises exception Tl if applied to the empty list nil:

- hd(nil); uncaught exception Hd - tl(nil); uncaught exception Tl

Consider the function

fun g(l) = hd(l) : : tl(l) handle Hd => nil; that behaves like the identity function on lists. The result of evaluating g(nil) is nil. Explain why. What makes the function g return properly without handling the exception Tl?

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Consider the function fun gl hdl tll handle hd gt nil
Reference No:- TGS01269935

Expected delivery within 24 Hours