-Could you please define the following functions and test them in a haskell by u
ID: 3602355 • Letter: #
Question
-Could you please define the following functions and test them in a haskell by using a bag module:
1)newBag returns a new bag with no elements (i.e., empty).
2)isEmpty takes a bag and returns True if the bag has no elements and returns False otherwise.
3)isElem takes an element and a bag and returns True if the element occurs in the bag and returns False otherwise.
4)size takes a bag and returns its cardinality (i.e., the total number of occurrences of all elements).
5)occursBag takes an element and a bag and returns the number of occurrences of the element in the bag.
Explanation / Answer
please finf below the code : i have only solve for 1,2,3,4,
1 :
2 :
Output: True if bag is empty
3: elemBag :: Eq a => a -> Bag a -> Bool
4 : lengthBag :: Bag a -> Int
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.