Question: namespace Homework 3 open System.Reflection.Metadata open System.Runtime.Intrinsics.Arm module HW 3 = type SET = | I of int list / / I [ 1 ;

namespace Homework3
open System.Reflection.Metadata
open System.Runtime.Intrinsics.Arm
module HW3=
type SET =
| I of int list // I [1;2;3]
| S of string list // S ["a";"b";"c"]
| IS of (int * string) list // IS [(1,"a");(2,"b")]
| II of (int * int) list // II [(1,2); (3,4); (5,6)]
| SS of (string * string) list // SS [("a","b"); ("c","d")]
| SI of (string * int) list // SI [("a",1); ("b",2); ("c",3)]
| SISI of ((string * int)*(string * int)) list // SISI [(("a",1),("b",2)); (("c",3),"d",4))]
| SIIS of ((string * int)*(int * string)) list // SIIS [(("a",1),(2,"b")); (("c",3),(4,"d"))]
// complete this function
let pairs L1 L2=
[]
// complete this function
let dist a L =[]
// cartesian product
let product s1 s2=
match (s1, s2) with
|(I s1, I s2)-> II (pairs s1 s2)// you need to write pairs
|(S s1, S s2)-> SS (pairs s1 s2)
|(I s1, S s2)-> IS (pairs s1 s2)
// you need to complete these cases
// The following four methods are incorrect and must be replaced!
let gtSx x y = true
// to do
let eqxIxx x y = true
// ot do
let selectSI x y = I []
// to do
let selectSIIS x y = I []
// to do
let rec isMember a L =
match L with
|[]-> false
| h::t when a=h -> true
| h::t -> isMember a t
let rec unionList l1 l2=
match l1 with
|[]-> l2
| h::t when not (isMember h l2)-> h::unionList t l2
| h::t -> unionList t l2
let union s1 s2=
match (s1, s2) with
|(I l1, I l2)-> I (unionList l1 l2)
|(IS l1, IS l2)-> IS (unionList l1 l2)
|(SISI l1, SISI l2)-> SISI (unionList l1 l2)
// you need to complete these cases
// to do
let gtIx x (a,_)= a > x
let gtxxxI x ((_,_),(_, a))= a > x
// let gtSx ???=???
// to do
// let eqIxx ???=???
// to do
let rec filter f L =
match L with
|[]->[]
| h::t when f h -> h::filter f t
| h::t -> filter f t
let selectIS s f =
match s with
| IS i -> IS (filter f i)
let selectSISI s f =
match s with
| SISI i -> SISI (filter f i)
let minus L1 L2=[]
// to do
let difference s1 s2=
match (s1,s2) with
|(I s1, I s2)-> I (minus s1 s2)// write the minus function
|(SI s1, SI s2)-> SI (minus s1 s2)
|(SISI s1, SISI s2)-> SISI (minus s1 s2)
// complete these cases

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!