Re: [Haskell-cafe] Seeking Control.Lens Combinator

2013-10-05 Thread Niklas Haas
On Fri, 4 Oct 2013 16:23:23 -0700, Charlie Paul charli...@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.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Seeking Control.Lens Combinator

2013-10-05 Thread Sebastiaan Visser
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 charli...@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

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Seeking Control.Lens Combinator

2013-10-04 Thread Charlie Paul
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
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe