[Haskell-cafe] Seeking Control.Lens Combinator
Sebastiaan Visser
haskell
Sat Oct 5 14:14:20 UTC 2013
Charles,
I know you specifically asked for a Control.Lens combinator and I don't have one for you, but I take the opportunity to show you how easy this is using fclabels:
tupleUp :: f :-> a
-> f :-> b
-> f :-> (a, b)
tupleUp a b = point $
(,) <$> L.fst >- a -- L.fst, L.snd are lenses from Data.Label.Base
<*> L.snd >- b
In fclabels you can use the Applicative instance (and Alternative for multi-constructor cases) to derive views like this. If you look at the structure it'll become clear how easily this scales up to different types of views.
This particular example uses total monomorphic lenses, but also works for partial lenses and polymorphic updates.
Maybe there is a similar way in Control.Lens to do this.
Sebastiaan
On Oct 5, 2013, at 1:23 AM, 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"?
>
> Thank you,
>
> Charles Paul
More information about the Haskell-Cafe
mailing list