Consider the following definition fun f a b c a if B Solut

Consider the following definition fun f (a, b, c) = a + (if B

Solution

Let\'s Consider the below initial type assignment.
type(a) = Ta
type(b) = Tb
type(c) = Tc
type(f) = T (*) (Ta, Tb, Tc)
Now we use the notation T(n) to denote the type of node n. We need to now determine the types by visiting each and every node:

1. When Visiting Node1:

type(f) = T (*) (Ta, Tb, Tc)
T(2) = T


2. When Visiting node2:

Node2 is a + node. The following constraint must be satisfied:
T(3) = T(2) = type(1)
We already know, that type(1) is int and T(2) = T.
Then we conclude that: T(3) = int
T(2) = int
T = int

3. When Visiting Node3:

Node3 is a + node. The following constraint must be satisfied:
Type(a) = T(3) = T(4)
We now know, that T(3)= int, so it implies that
Type (a) = Ta = Int
T(4) = int

4. When Visiting Node4:

It is an IF Expression node. The following constraint must be satisfied:
T(5) = bool
Type(b)= Tb = T(4) = Int
Type(c)= Tc = T(4) = Int

5. When Visiting Node5:

Node5 is a > node (relational operator). The following constraint must be satisfied:
T(5) = bool
Type(a) = Type(b) = numeric.

The above constraints are satisfied by the types we already calculated:
T(5) = bool
type(b) = int
type(c) = int

Therefore, type(f) = (int,int,int) -> int, where
type(a) = int, type(b) = int, type(c) = int

 Consider the following definition fun f (a, b, c) = a + (if B SolutionLet\'s Consider the below initial type assignment. type(a) = Ta type(b) = Tb type(c) = Tc

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site