Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In SML, all references must point to real values in the heap. In other words, SML does not support implicit null pointers in place of
In SML, all references must point to real values in the heap. In other words, SML does not support implicit null pointers in place of a reference. Instead, the SML data type declaration datatype 'a option = NONE | SOME of 'a; defines the generic type 'a option of references which could either point to nothing (represented by the NONE constructor containing no data) or point to some actual 'a in the heap (represented by the SOME constructor containing a value of type 'a). For example, the integer division operation x div y will raise an exception when the divisor y is 0. A safe version of division, which never raises an exception, can be written in SML as: fun safe_div(x, 0) = NONE | safe_div(x, y) = SOME(x div y);
which takes a pair of ints and returns an int option. (a) What is the difference between the result of evaluating 10 div 0 versus safe_div(10, 0)? (b) What is the difference between the result of evaluating 10 div 5 versus safe_div(10, 5)? (c) What happens when you try to evaluate 2 * (10 div 5)? What happens when you try to evaluate 2 * (safe_div(10, 5))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started