subject

Programming with Lists Multisets, or bags, can be represented as list of pairs (x, n) where n indicates the number of occurrences of x in the multiset. type Bag a - [(a, Int)] For the following exercises you can assume the following properties of the bag representation. But note: Your function definitions have to maintain these properties for any multiset they produce! (1) Each element x occurs in at most one pair in the list. (2) Each element that occurs in a pair has a positive counter. As an example consider the multiset {2, 3, 3,5,7,7,7,8), which has the following representation (among others) Note that the order of elements is not fixed. In particular, we cannot assume that the elements are sorted. Thus the above list representation is just one example of several possible. (a) Define the function ins that inserts an element into a multiset. ins :: Eq a => a-> Bag a-> Bag a (Note: The class constraint "Eq a =>" restricts the element type a to those types that allow the comparison of elements for equality with --.) (b) Define the function del that removes an element from a multiset. del Eq a -> Bag a Bag a (c) Define a function bag that takes a list of values and produces a multiset representation bag :: Eq a => [a] -> Bag a For example, with xs7,3,8,7,3,2,7,5] we get the following result. > bag xs (Note: It's a good idea to use of the function ins defined earlier.) (d) Define a function subbag that determines whether or not its first argument bag is contained in the second. subbag Eq aBag a Bag aBool Note that a bag b is contained in a bag b' if every element that occurs n times in b occurs also at least n times in b'. (e) Define a function isbag that computes the intersection of two multisets. isbag Eq Bag a ->Bag a -Bag a (0) Define a function size that computes the number of elements contained in a bag. sizeBag a ->Int

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 06:00
Which statistical function in a spreadsheet you to see how far each number varies, on average, from the average value of the list?
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
You have been supporting csm tech publishing's windows server 2016 server network for over a year. the office has two windows server 2016 servers running active directory and a number of other roles. management has informed you that a small sales office is opening in the same building three floors up. the sales manager wants to install a sales application on a server located in the sales office. this server will have limited physical security because there's no special room dedicated for it, which means it will be accessible to non-it personnel and visitors. you're considering installing windows server 2016 server core on the new server because accessing its console regularly probably won't be necessary, and this server will be managed from one of the other csm tech publishing servers. what are the benefits and drawbacks of using server core for this branch office? what are some things you should do to set up this server management environment?
Answers: 1
question
Computers and Technology, 24.06.2019 06:50
What are the things you are considering before uploading photos on social media?
Answers: 1
question
Computers and Technology, 24.06.2019 13:00
Your mom wants to purchase a laptop computer. she said she wants her new computer to be able to play her dvds so she can listen to music and wants to know what type of optical drives will play her disk. which type of drive should she look for?
Answers: 1
You know the right answer?
Programming with Lists Multisets, or bags, can be represented as list of pairs (x, n) where n indica...
Questions
question
English, 11.12.2019 04:31
question
Mathematics, 11.12.2019 04:31
Questions on the website: 13722360