Question: Could you please define the following functions in a haskell by using a bag module: 1)listToBag takes a list of elements and returns a bag
Could you please define the following functions in a haskell by using a bag module:
1)listToBag takes a list of elements and returns a bag containing exactly those elements. The number of occurrences of an element in the list and in the resulting bag is the same.
2)bagToList takes a bag and returns a list containing exactly the elements occurring in the bag. The number of occurrences of an element in the bag and in the resulting list is the same.
3)insertElem takes an element and a bag and returns the bag with the element inserted. Bag insertion either adds a single occurrence of a new element to the bag or increases the number of occurrences of an existing element by one.
4)deleteElem takes an element and a bag and returns the bag with the element deleted. Bag deletion removes a single occurrence of an element from the bag, decreases the number of occurrences of an existing element by one, or does not change the bag if the element does not occur.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
