Although our immutable Bloom filter API
is straightforward to use once we have created a Bloom
fromList function leaves
some important decisions unresolved. We still have to choose a function
that can generate many hash values and determine what the capacity of a
Bloom filter should be:
-- file: BloomFilter/Easy.hs easyList :: (Hashable a) => Double -- false positive rate (between 0 and 1) -> [a] -- values to populate the filter with -> Either String (B.Bloom a)
Here is a possible “friendlier” way to create a Bloom filter. It leaves responsibility for hashing values in the hands of a typeclass, Hashable. It lets us configure the Bloom filter based on a parameter that is easier to understand—namely the rate of false positives that we are willing to tolerate. And it chooses the size of the filter for us, based on the desired false positive rate and the number of elements in the input list.
This function will, of course, not always be usable—for example, it will fail if the length of the input list is too long. However, its simplicity rounds out the other interfaces we provide. It lets us offer our users a range of control over creation, from entirely imperative to completely declarative.
In the export list for our module, we
re-export some names from the base
BloomFilter module. This allows casual
users to import only the
BloomFilter.Easy module and have access to all of the types and functions they are likely ...