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 ) [ ( ]

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 a 0.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/2 point )^' a ->(a -> b^' b)->'b (c)(1/. point)(a -> b^' b)->' a ->' b -> b 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: 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 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+(y z))0 x 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 1 t 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:: x 5-> f x (fold right f x 5 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 with AI-Powered 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

Students also viewed these Databases questions