Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Code should be written in Haskell The following problems are to implement mathem

ID: 3887604 • Letter: C

Question

Code should be written in Haskell

The following problems are to implement mathematical sets and their operations using Haskell lists. A set is an unordered collection of elements (objects) without duplicates, whereas a list is an ordered collection of elements in which multiplicity of the same element is allowed. Let us define Set as a type synonym for lists as follows: [Ref. Chapter 8, in particular, Section 8.1 Type declarations.] type Set a [a] Even though the two types - Set a and [a] - are the same to the Haskell compiler, they communicate to the programmer that values of the former are sets and those of the latter are Problem 11. (10 points) [Read Chapters 3, 4, and 6.] Set constructor. Write a recursive function that constructs a set. Constructing a set from a list simply means removing all duplicate values. Use isElement in the definition mkSet :: Eq a=> [a] -> Set a All the remaining functions can assume that their incoming set arguments are indeed sets (i.e, lists that do not contain duplicates), and correspondingly, your implementations must guarantee this property for the sets that are returned as results Problem 12. (5 points) Read Chapters 3-6.] Write a recursive function size that returns the number of elements in a set. Do not use the library function length size : Set a-Int

Explanation / Answer

type Set a = [a] mkSet :: Eq a => [a] -> Set a mkSet [] = [] mkSet (x:xs) | x `isElement` xs = mkSet xs | otherwise = [x] ++ mkSet xs size :: Set a -> Int size [] = 1 size a = myLength a subset :: Eq a => Set a -> Set a -> Bool subset [] _ = True subset (x:xs) a | x `isElement` a = subset xs a | otherwise = False setEqual :: Eq a => Set a -> Set a -> Bool setEqual [] [] = True setEqual _ [] = False setEqual [] _ = False setEqual (x:xs) (y:ys) | x `isElement` (y:ys) && y `isElement` (x:xs) = not (subset xs ys) | otherwise = False powerset :: Set a -> Set (Set a) powerset [] = [] powerset (x:xs) = [x:xs] ++ [[x]] ++ powerset xs

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote