Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . Briefly explain why the following expressions induce a type error? ( a ) ( 1 / point ) [ ( I

1. Briefly explain why the following expressions induce a "type error"? (a)(1/ point)[("I",4.0) ; ("R",0.0) ; ("S",1)]
2
(b)(1/ point)2
type a option = Some of a | None letfa=
if a <0.0 then None else a
2. Provide expressions (without type annotations) that have the following types: (a)(1/ point) int > int list > bool list
2
(b)(1/ point)a >( a>b)>b 2
(c)(1/ point)(a>b)>a >b > bool 2
(d)(1/ point)a >(a >a)>a >a 2
CS314
Final, Page 3 of 1216
th
Dec, 2023
(e)(1/ point)(a > int)>a > int 2
(f)(1/ point)a >(a >b) list >b list .2
(g)(1point) Defineafunctionfthatwhenusedinthefollowingexpressionwillnotproduce any type errors:
fold_left f ([],0)[5;4;3;2;1]
The implementation and type of fold_left are given for reference, below.
let rec fold_left f a l = match l with |[]> a
| h::t > fold_left f (f a h) t
(h)(1point) Whatwouldyouputinplacefortheblanksuchthatthefollowingcodereturns 44?
let f = fun x y z >
List.fold_left (fun acc e > acc + e +(y z))0 x in
f [1;1;1;1]_________4
CS314 Final, Page 4 of 1216
th
Dec, 2023
(i)(1 point) What would you put in place for the blank such that sublist [1]0=[] and sublist [1; 0; 2; 3]1=[1; 0]?
let sublist l t =
fold_right (fun x a >____________________) l []
The implementation of fold_right is given for reference, below.
let rec fold_right f l acc = match l with |[]> acc
| x::xs > f x (fold_right f xs acc)
(j)(1 point) What would you put in place for the blank such that the following program returns (10.0,40.0)?
type taxpayer =
| Person of float
| Company of float
let tax y =
let income_tax a x =__________ in
match y with
| Person i > income_tax i 0.1
| Company j > income_tax j 0.2 in
( tax ( Person 100.0), tax (Company 200.0))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions