Consider the following functions written in ml exception


Consider the following functions, written in ML:

exception Excpt of int;

fun twice(f,x) = f(f(x)) handle Excpt(x) => x;

fun pred(x) = if x = 0 then raise Excpt(x) else x-1; fun dumb(x) = raise Excpt(x);

fun smart(x) = 1 + pred(x) handle Excpt(x) => 1;

What is the result of evaluating each of the following expressions?

(a) twice(pred,1);

(b) twice(dumb,1);

(c) twice(smart,0);

In each case, be sure to describe which exception gets raised and where.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Consider the following functions written in ml exception
Reference No:- TGS01269929

Expected delivery within 24 Hours