I try to write a comparison operator greater-than-equals for two lens getters with type
(.>=.) :: Ord a => Getting a s a -> Getting a s a -> Getting Bool s Bool
I have a working solution for a getter on the left side and a value on the right side (no . on the right side of the operator .>=)
left .>= right = left . to (>= right)
I tried
left .>=. right = (>=) <$> use left <*> use right
but it has type
(.>=.) :: (Ord a, MonadState s f) => Getting a s a -> Getting a s a -> f Bool
How can I get the desired return type Getting Bool s Bool instead of f Bool?
You're close with this:
First, use
viewin instead ofuse;useis for getting from state (hence theMonadStateconstraint), which doesn't seem relevant here.That gives you a function (
MonadReader s f => f Boolspecializes tos -> Bool), so now you need to turn this into aGettingwithto.(And
(Contravariant f, Profunctor p) => Optic' p f s Boolspecializes toGetting Bool s Bool, so this is what you want.)