well-typed / optics

Optics as an abstract interface
374 stars 24 forks source link

over' and iover' pretend to work with incompatible optics #473

Open treeowl opened 1 year ago

treeowl commented 1 year ago
ghci> length $ over' mapped id [undefined, undefined]
2

Oops. I'm currently working on adding over', iover', and relatives to lens. The choice I've made over there is not to add a Settable Solo instance, to avoid this very problem. I don't know how these optics work, but the uses of unwrapIdentity' in the Mapping (Star Identity') and Mapping (IxStar Identity') instances look really fishy. What goes wrong if those instances are removed, and over' and iover' are declared to need traversals rather than setters?

Additional surprising uses:

failover' and ifailover' both do things like

if visited
  then Just (unwrapIdentity' t)
  else Nothing

Should those be like this?

if | visited
   , Identity' () v <- t
   -> Just v
   | otherwise
   -> Nothing

or (using Solo)

if | visited
   , Solo v <- t
   = Just v
   | otherwise
   = Nothing

While you're in the ballpark, Identity' is quite an awkward type, and there's really no need for such complication.

Identity'  ~=  Solo -- Best Solo source is OneTuple, which handles all the compat mess
unwrapIdentity' ~= getSolo
wrapIdentity' ~= (Solo $!)