I am curious about Eq instance for lenses. Lenses are functions. It is hard to compare arbitrary functions, but lenses are special class of functions.
I am thinking about using QuickCheck Arbitrary instances for s type:
lensesAreEqual ::
(Arbitrary a, Eq a) =>
Lens' s a ->
Lens' s a ->
Gen Bool
lensesAreEqual l1 l2 =
and <$> forM [0..100] $ \_ -> do
s <- arbitrary
pure $ s ^. l1 == s ^.l2
I can hind lensesAreEqual monad behind unsafePerformIO for a neat Eq instance.
Does anybody know better solution?
Don't do this. Instead, define a real data type with the usual
Equality, together with an interpretation function:(This is what was meant in the comments about "defunctionalization".)