I thought it would be neat to have size function constrained to
members of Bounded that would automatically choose which method
depending on the extent of the domain of the set. So, a small set
could be computed by the very fast method and the compiler would be
able to do the dispatch as part of constant folding.
This is what I came up with. It works, but it seems kind of forced.
I wonder if there is a better way.
sizeB :: (Bounded a,Enum a) => a -> Set a -> Int
sizeB e =
case fromEnum $ maxBound `asTypeOf` e of
x | x <= 12 -> \(Set w) -> fromIntegral $ c12 $ fromIntegral w
x | x <= 24 -> \(Set w) -> fromIntegral $ c24 $ fromIntegral w
x | x <= 32 -> \(Set w) -> fromIntegral $ c32 $ fromIntegral w
_ -> \(Set w) -> bitcount 0 w