I am trying to write a small file to try out a bag-like data structure. So far, my code is as follows:
data Fruit = Apple | Banana | Pear deriving (Eq, Show) data Bag a = EmptyBag | Contents [(a, Integer)] emptyBag :: Bag a emptyBag = EmptyBag unwrap :: [a] -> a unwrap [x] = x isObject theObject (obj, inte) = theObject == obj count :: Bag a -> a -> Integer count (Contents [xs]) theObject = snd (unwrap (filter (isObject theObject) [xs])) count EmptyBag _ = 0
But when I try to run it, I get the error Failed to deduce (Eq a) from the context () arising from using "isObject" when ....
If I take the count function and call snd (spread (filter (isObject Banana) [(Apple, 1), (Banana, 2)])) it happily returns 2.
Any tips on why this is so, or tips on writing such a data structure would be greatly appreciated.
Owen source share