subject
Engineering, 21.04.2020 22:33 KENYONWASHINGTON868

Exercise 1. 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: 3

Another question on Engineering

question
Engineering, 03.07.2019 15:10
Ahouse has the following electrical appliance usage (1) single 40w lamp used for 4 hours per day (2) single 60w fan used for 12 hours per day (3) single 200w refrigerator that runs 24 hours per day with compressor run 12 hours and off 12 hours find the solar power inverter size in watt with correction factor of 1.25.
Answers: 1
question
Engineering, 04.07.2019 18:10
Steel is coated with a thin layer of ceramic to protect against corrosion. what do you expect to happen to the coating when the temperature of the steel is increased significantly? explain.
Answers: 1
question
Engineering, 04.07.2019 18:10
At 12 noon, the count in a bacteria culture was 400; at 4: 00 pm the count was 1200 let p(t) denote the bacteria cou population growth law. find: (a) an expression for the bacteria count at any time t (b) the bacteria count at 10 am. (c) the time required for the bacteria count to reach 1800.
Answers: 1
question
Engineering, 04.07.2019 18:10
Water at the rate of 1 kg/s is forced through a tube with a 2.5 cm inner diameter. the inlet water temperature is 15°c, and the outlet water temperature is 50°c. the tube wall temperature is 14°c higher than the local water temperature all along the length of the tube. what is the length of the tube?
Answers: 3
You know the right answer?
Exercise 1. Programming with Lists Multisets, or bags, can be represented as list of pairs (x, n) wh...
Questions
Questions on the website: 13722363