Question

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

Était-ce utile?

La solution

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.

Autres conseils

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.

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top