Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Provide expressions ( without type annotations ) that have the following types ( a > int ) > a > int ( f ) (

Provide expressions (without type annotations) that have the following types
( a > int )>a > int
(f)(1/2 point)a >( a >b) list >b list .
(g)(1 point) Define a function f that when used in the following expression will not produce
any type errors:
f o l d _ l e f t f ([],0)[5 ; 4 ; 3 ; 2 ; 1]
The implementation and type of fold_le are given for reference, below.
l e t r e c f o l d _ l e f t f a l = match l with
|[]> a
| h : : t > f o l d _ l e f t f ( f a h ) t
(h)(1 point) What would you put in place for the blank such that the following code returns
44?
l e t f = fun x y z >
L i s t . f o l d _ l e f t ( fun a c c e > a c c + e +( y z ))0 x in
f [1 ; 1 ; 1 ; 1]_________4
hat would you put in place for the blank such that sublist [1]0=[] and
sublist [1; 0; 2; 3]1=[1; 0]?
l e t s u b l i s t l t =
f o l d _ r i g h t ( fun x a >____________________) l []
The implementation of fold_right is given for reference, below.
l e t r e c f o l d _ r i g h t f l a c c = match l with
|[]> a c c
| x : : x s > f x ( f o l d _ r i g h t f x s a c c )
(j)(1 point) What would you put in place for the blank such that the following program
returns (10.0,40.0)?
type t a x p a y e r =
| P e r s o n of f l o a t
| Company of f l o a t
l e t t a x y =
l e t i n c o m e _ t a x a x =__________ in
match y with
| P e r s o n i > i n c o m e _ t a x i 0.1
| Company j > i n c o m e _ t a x j 0.2 in
( t a x ( P e r s o n 100.0), t a x ( 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