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, 24.06.2019 03:00
Will do anything for brainlest so can you guys me out i will try my best to you out
Answers: 1
question
Computers and Technology, 24.06.2019 05:30
If you combine two cells into one, what action are you performing? a.  adding a new row or column      b.  splitting the cells      c.  removing a new row or column      d.  merging the cells
Answers: 2
question
Computers and Technology, 24.06.2019 12:50
When is it most apprpriate for a development team to change the definition of done
Answers: 1
question
Computers and Technology, 24.06.2019 21:40
Which of these is not a type of socket? aga (alternating grid array) pga (pin grid array) spga (staggered pin grid array) lga (land grid array)
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
History, 17.06.2021 17:30
question
History, 17.06.2021 17:30
question
Mathematics, 17.06.2021 17:30
Questions on the website: 13722362