lens icon indicating copy to clipboard operation
lens copied to clipboard

Test `lens-compose` / `compose` relationship

Open jackfirth opened this issue 10 years ago • 1 comments

lens-compose should compose lenses in the same order as compose (it does currently, but it should be documented in tests that this order is preferred). This is to preserve the general assumption that lenses work like functions, but with the added "inverting" behavior for bidirectional programming. This assumption means the following should all be true:

  • When only using lens-view, lenses should operate like the getter functions they mimic. Thus, (lens-view (lens-compose l ...) target) should be equivalent to ((compose (lens-view l _) ...) target).
  • Applicable lenses behave like getters literally, so ((lens-compose l ...) target) should be equivalent to ((compose l ...) target) when using applicable lenses.
  • lens-thrush should invert direction just like thrush inverts function composition direction.

This issue is more to document why I made this ordering decision, as I recently noticed that Ramda's lensCompose uses the "wrong order".

jackfirth avatar Feb 04 '16 05:02 jackfirth

Update: Ramda uses this order because Haskell does - Haskell does because it uses van Laarhoven lenses, which are functions and lens composition is the same as function composition. The details of the Laarhoven representation bring about the "composition inversion" behavior. I consider this an unfortunate consequence of the implementation, and Racket lenses are bound by no such implementation restrictions.

jackfirth avatar Feb 04 '16 05:02 jackfirth