[Haskell-cafe] Seeking Control.Lens Combinator
Niklas Haas
haskell
Sat Oct 5 08:28:01 UTC 2013
On Fri, 4 Oct 2013 16:23:23 -0700, Charlie Paul <charlieap at gmail.com> wrote:
> Hello,
>
> I'm looking for a combinator along the lines of
> (&&&) :: Lens' a b -> Lens' a b' -> Lens' a (b,b')
> I can see how it could lead to lenses that don't follow the laws, but
> for Lenses which are somehow independent (like _1 and _2), it works
> perfectly well. Is there a way in lens to specify this "independence"?
If you don't mind violating the laws (ie. ensuring you access fields
non-independently), then you could do this manually with a
splitting/joining ?isomorphism? at one end, and joining the other lenses
using ?alongside?. For example:
iso (join (,)) (fst *** snd).alongside _1 _2 :: Lens (a,b) (a',b') (a,b) (a',b')
Of course, this particular lens is utterly trivial (it's just id). And I'm
not sure how much sense it makes to extend this pattern to more
complicated cases.
More information about the Haskell-Cafe
mailing list