Write an ML (SML; Standard Meta Language) function getith(i,L) that takes an int
ID: 3591804 • Letter: W
Question
Write an ML (SML; Standard Meta Language) function getith(i,L) that takes an integer i and a list L, and returns the ith element on list L. Write exception definition, raise and handler if i is < 1 or if i > length of L.Write an ML (SML; Standard Meta Language) function getith(i,L) that takes an integer i and a list L, and returns the ith element on list L. Write exception definition, raise and handler if i is < 1 or if i > length of L.
Write an ML (SML; Standard Meta Language) function getith(i,L) that takes an integer i and a list L, and returns the ith element on list L. Write exception definition, raise and handler if i is < 1 or if i > length of L.
Explanation / Answer
fun getith =
if i<1 or i>len(L) then raise Exception('ut of range error') else return L[i]
#Calling of ML Function
getith = i,L