haskelllenses

What are the advantages and disadvantages of using lenses?


Lenses don't seem to have any disadvantages while having significant advantages over standard Haskell: Is there any reason I shouldn't use lenses wherever possible? Are there performance considerations? Additionally, does template Haskell have any significant overhead?


Solution

  • Lenses form an alternative to using direct closures over data constructors. Lenses therefore have approximately the same caveats as using functions and data constructors directly.

    Some of the cons because of this:

    And the pros:

    Lenses are not always isomorphic to closures over data constructors, however. Here are some of the differences (taking data-lens as the implementation here):

    Template Haskell code runs at compile time, and does not affect the runtime performance of lenses whatsoever.