The following function -
mayBeMempty :: (Eq a, Semigroup a) => a -> a -> Bool
mayBeMempty candidate ref = candidate <> ref == ref
Is a (less efficient) generalization of Data.Set.isSubSetOf
. It checks if the first argument is "contained" in the second one and always returns True
when the first argument is mempty
(when it returns False
it is known to not be mempty
).
Does anyone know if this function or concept already exist under some name or even an existing type-class (in which case it would not be less efficient than isSubSetOf
)?
PartialOrd
's leq
is what I was looking for.
IIUC, a difference is that it is not designed to fit the rules as I described for Semigroup
, but instead it's designed to work in this manner with Lattice
which is defined in the same package, which is similar to a semigroup in some ways but better fits things like sets where merging something with itself results in itself.