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) (I/2 point) [(], 4.0); (R, 0.0); (S, 1)] (b) ( 1 point) type

image text in transcribedimage text in transcribedimage text in transcribed 1. Briefly explain why the following expressions induce a "type error"? (a) (I/2 point) [("]", 4.0); ("R", 0.0); ("S", 1)] (b) ( 1 point) type 'a option - Some of 'a | None let f a - if a a0.0 then None else a. 2. Provide expressions (without type amotations) that have the following types: (a) ( 1 point) int int list bool list (b) (1/2point)a(abb) 'b (c) (1/ point) (abb)abb bool (e) (//2 point )(a int ) a int (f) (1/2 point) 'a ('a 'b) list 'b list. (g) (1 point) Defme a function f that when used in the following expression will not produce any type errors: foldleftf([],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 I with I] a I h::t fold left f(f a h)t (h) (1 point) What would you put in place for the blank such that the following code returns 44 ? let f - fun x y z List. fold left (fun acc e acc+e+(yz) ) 0x in f[1;1;1;1] 4 (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 1t fold right (fun x a ) [ [] The implementation of fold right is given for reference, below. let rec fold right f [ acc - match [ with I [] acc x::x5fx (fold right fx5 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 taxy let income tax a x in match y with | Person i income tax i 0.1 | Company j income tax j0.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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions