The following data definition defines such decision trees for any generic type of
data DIree a = Leaf Bool | Node (a-›Bool)
(DIree a) (DIree a)
and here is an implementation of the decision tree shown in Figure 1:
Copyright By PowCoder代写 加微信 powcoder
DIree FruitBox
Node (\ (f,
n>3) (Leaf False) (Leaf True) )
(Leaf False)
Q5. Use recursion to write a function applyDTree which will apply a decision tree
to an object to return a Boolean value. For example,
applyDTree
d1 (Banana, 4) will return False
applyDIree d1 (Apple, 3) will return True
Page 2 of 5
Your function needs to be polymorphic, i.e. it can be used on any type a. Include the
type declaration for applyDIree.
[12 marks]
Q6. Write code to apply decision tree d1 to x1 and output the Boolean value to
variable name b1.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com