From the documentation:
Try the first
Traversal(orFold), falling back on the secondTraversal(orFold) if it returns no entries.This is only a valid
Traversalif the secondTraversalis disjoint from the result of the first or returns exactly the same results.
Is there a simple example of an invalid traversal generated by failing and a test case demonstrating it?
For the counterexample, let us first define a new data type, for which we generate traversals using
makePrisms:_A :: Traversal T Tis now a valid traversal. Now, construct a new traversal usingfailing:Notice that
(C & t .~ A C) ^.. t = [C], which looks like it fails a traversal law (you don't "get what you put in"). Indeed, the second traversal law is:which is not satisfied, as can be seen with the following choice for
fandg:Then:
While:
So there is indeed a case where
failingwith valid traversals doesn't produce a valid traversal.