10

Possible Duplicate:
lenses, fclabels, data-accessor - which library for structure access and mutation is better

I'm going to use and learn a Lens package on my next Haskell project. I had almost decided on the Data.Lens package when I found this post which mentions van Laarhoven Lenses in the Control.Lens package.

I don't really understand the differences enough yet to decide which one to use. Which package would you suggest I learn/use on a real world project?

Thanks.

lenses, fclabels, data-accessor - which library for structure access and mutation is better

Community
  • 1
  • 1
MFlamer
  • 2,340
  • 2
  • 18
  • 25
  • 4
    What is wrong with that SO link's answer? – Pubby Nov 08 '12 at 05:19
  • Something *can* be wrong with that SO link's answer, but if you don't tell us what you want to know that isn't in that answer you're not going to get the information you're after. – Ben Nov 08 '12 at 05:41
  • 2
    I'm guess it's a third point of view I'm looking for. That SO post was written by the creator of both packages. He does give some comparison between the 2 but its a little over my head. – MFlamer Nov 08 '12 at 06:30
  • 3
    The other post doesn't even mention Control.Lens, so I don't see how this is a duplicate. – Adam Gordon Bell Nov 16 '12 at 00:13

3 Answers3

13

Control.Lens is almost certainly what you want. Data.Lens came first, and is simpler, but Control.Lens has many advantages, and is being actively developed.

Other than lenses, Control.Lens has many related types, like traversals (a traversal is like a lens that can refer to n values instead of just one), folds, read/modify-only lenses, indexed lenses, isomorphisms... It also comes with a much larger library of useful functions and predefined lenses for standard library types, Template Haskell to derive lenses, and a bunch of code for other things like generic zippers and uniplate-style generic traversal.

It's a big library -- you don't have to use all of it, but it's nice to have the thing you want already written.

The main advantage of Data.Lens is that it's simpler, and as such doesn't require extensions beyond Haskell 98. But note that if you just want to export a Control.Lens-style lens from a library, you can do it without leaving Haskell 98 -- in fact, without depending on the package at all.

shachaf
  • 8,890
  • 1
  • 33
  • 51
  • After a little more research last night, I came to the same conclusion. Thanks for the excellent responses. – MFlamer Nov 08 '12 at 21:19
6

If you're dealing with a Real World Project (tm), I'd highly recommend Control.Lens. Edwardk has put a lot of recent effort into it, and I'm sure he'd love to hear about your use case. In my opinion, this is going to become the canonical Lens library. I believe it's safe to say that everything you can do with Data.Lens, you can do with Control.Lens.

Dan Burton
  • 53,238
  • 27
  • 117
  • 198
0

Data.Lens is much simpler and easier to work with. Control.Lens has a very large number of modules and uses language extensions to get the job done.

singpolyma
  • 10,999
  • 5
  • 47
  • 71