Reputation: 24774
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
)?
Upvotes: 1
Views: 100
Reputation: 24774
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.
Upvotes: 0
Reputation: 2288
I have searched with Hoogle and think there is no pre-implemented version of this.
I don't really see how it could be made more efficient, TBH.
Upvotes: 0