Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 . Briefly explain why the following expressions induce a type error? ( a ) ( 1 / point ) [ ( I
Briefly explain why the following expressions induce a "type error"? a pointI ; R ; S
b point
type a option Some of a None letfa
if a then None else a
Provide expressions without type annotations that have the following types: a point int int list bool list
b pointa abb
c pointaba b bool
d pointa a aa a
CS
Final, Page of
th
Dec,
e pointa inta int
f pointa a b list b list
gpoint Defineafunctionfthatwhenusedinthefollowingexpressionwillnotproduce any type errors:
foldleft f ;;;;
The implementation and type of foldleft are given for reference, below.
let rec foldleft f a l match l with a
h::t foldleft f f a h t
hpoint Whatwouldyouputinplacefortheblanksuchthatthefollowingcodereturns
let f fun x y z
List.foldleft fun acc e acc e y z x in
f ;;;
CS Final, Page of
th
Dec,
i point What would you put in place for the blank such that sublist and sublist ; ; ; ;
let sublist l t
foldright fun x a l
The implementation of foldright is given for reference, below.
let rec foldright f l acc match l with acc
x::xs f x foldright f xs acc
j point What would you put in place for the blank such that the following program returns
type taxpayer
Person of float
Company of float
let tax y
let incometax a x in
match y with
Person i incometax i
Company j incometax j in
tax Person tax Company
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