Question: In the Client module, write a function sum : I.t -> int that takes a set of integers and returns their sum. Hint: Use I.fold.

In the Client module, write a function sum : I.t -> int that takes a set of integers and returns their sum. Hint: Use I.fold. Sample solution is one line. Note that you will not be able to test your code effectively until you do at least one of problems 5 and 6. module type INTSET = sig type t (* abstract type for sets of integer *) val empty : t (* the empty set *) int-> -> boolint > t -> bool val contains : int -> t -> bool (* checks if an element is in the set *) int -> -> tint ->t->t val insert : int -> t ->t (* returns a new set with the given element added *) int ->t-> tint ->t->t val remove : int > t ->t (* returns a new set with the given element removed *) ('a -> int ->'a) -> 'a ->t-> 'a (a -> int -> 'a) -> ->t -> 'a val fold : ('a > int -> 'a) (* "combine" all the elements via the given func. *) || | 'a -> t -> 'a (* note the order of combination is unspecified *) t-> stringit -> string val to_string : t -> string (* return a string in the format {x1, xn}. *) (* in this string, the elements should be in *) (* sorted order. *) end (* You don't need to understand these next few lines. They make it so Client can work with any implementation of INTSET. In the body of Client, there is a module I in scope. The only thing the body of Client knows about I is that it implements the module type INTSET. *) module Client (I : INTSET) : sig val sum : I.t -> int val to_list : I.t -> int list end = struct (* We don't know what I is, but it satisfies the signature INTSET *) 1.t -> int It -> int let sum (s : I.t) : int = failwith "sum: not implemented" In the Client module, write a function sum : I.t -> int that takes a set of integers and returns their sum. Hint: Use I.fold. Sample solution is one line. Note that you will not be able to test your code effectively until you do at least one of problems 5 and 6. module type INTSET = sig type t (* abstract type for sets of integer *) val empty : t (* the empty set *) int-> -> boolint > t -> bool val contains : int -> t -> bool (* checks if an element is in the set *) int -> -> tint ->t->t val insert : int -> t ->t (* returns a new set with the given element added *) int ->t-> tint ->t->t val remove : int > t ->t (* returns a new set with the given element removed *) ('a -> int ->'a) -> 'a ->t-> 'a (a -> int -> 'a) -> ->t -> 'a val fold : ('a > int -> 'a) (* "combine" all the elements via the given func. *) || | 'a -> t -> 'a (* note the order of combination is unspecified *) t-> stringit -> string val to_string : t -> string (* return a string in the format {x1, xn}. *) (* in this string, the elements should be in *) (* sorted order. *) end (* You don't need to understand these next few lines. They make it so Client can work with any implementation of INTSET. In the body of Client, there is a module I in scope. The only thing the body of Client knows about I is that it implements the module type INTSET. *) module Client (I : INTSET) : sig val sum : I.t -> int val to_list : I.t -> int list end = struct (* We don't know what I is, but it satisfies the signature INTSET *) 1.t -> int It -> int let sum (s : I.t) : int = failwith "sum: not implemented
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
