
(I sent this to 'libraries' but Kim-Ee suggested adding Café, where so many smart people hang out.) Friends Some of you will know that I've promised to give a talk about Edward's lens libraryhttp://hackage.haskell.org/package/lens at the Haskell Exchangehttp://skillsmatter.com/event/scala/haskell-exchange in London next Wednesday (9th). I did this to give everyone (including me) a break from GHC hackery, and also to force me to learn about this lens voodoo that everyone is twittering about. Edward generously gave me quite a bit of one-to-one attention last week (my hair is still standing on end), but this message is to ask your help too. Specifically, I'd like to give some compelling use-cases. If you are using the lens library yourself, could you spare a few minutes to tell me how you are using it? I expect to cover Lens and Traversal but not Prism. The use-case everyone starts with is nested records, but I'd like to go beyond that. The next levels seem to be: · Lenses as views of data that isn't "really there" e.g. regarding a record with rectangular coordinates as having polar coordinates too. · Lenses and Traversals that focus on elements of finite maps (Control.Lens.At) What else? I'm sure you are using them in all sorts of cool ways that I would never think of, and I'd love to know. Please don't tell me anything secret! To give everyone the benefit I may just concatenate all the replies and send to you all, so please say if you don't want me to do that with yours. And don't burn too many cycles on this...I don't want to waste your time, and I can always get back to you if I can't understand what you say. Sooner is better than later...Weds is coming. Simon "Edward's prophet" PJ

Hi Simon, An interesting use case is my time-lens library. http://hackage.haskell.org/package/time-lens-0.3/docs/Data-Time-Lens.html You can do things like
modL minutes (+5) (TimeOfDay 16 57 13) 17:02:13
But one has to be somewhat lenient about the lens laws here.
Roman
* Simon Peyton-Jones
(I sent this to 'libraries' but Kim-Ee suggested adding Café, where so many smart people hang out.)
Friends
Some of you will know that I've promised to give a talk about Edward's lens libraryhttp://hackage.haskell.org/package/lens at the Haskell Exchangehttp://skillsmatter.com/event/scala/haskell-exchange in London next Wednesday (9th). I did this to give everyone (including me) a break from GHC hackery, and also to force me to learn about this lens voodoo that everyone is twittering about. Edward generously gave me quite a bit of one-to-one attention last week (my hair is still standing on end), but this message is to ask your help too.
Specifically, I'd like to give some compelling use-cases. If you are using the lens library yourself, could you spare a few minutes to tell me how you are using it? I expect to cover Lens and Traversal but not Prism.
The use-case everyone starts with is nested records, but I'd like to go beyond that. The next levels seem to be:
· Lenses as views of data that isn't "really there" e.g. regarding a record with rectangular coordinates as having polar coordinates too.
· Lenses and Traversals that focus on elements of finite maps (Control.Lens.At)
What else? I'm sure you are using them in all sorts of cool ways that I would never think of, and I'd love to know.
Please don't tell me anything secret! To give everyone the benefit I may just concatenate all the replies and send to you all, so please say if you don't want me to do that with yours.
And don't burn too many cycles on this...I don't want to waste your time, and I can always get back to you if I can't understand what you say. Sooner is better than later...Weds is coming.
Simon "Edward's prophet" PJ
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 3 October 2013 10:57, Roman Cheplyaka
An interesting use case is my time-lens library. http://hackage.haskell.org/package/time-lens-0.3/docs/Data-Time-Lens.html
You can do things like
modL minutes (+5) (TimeOfDay 16 57 13) 17:02:13
But one has to be somewhat lenient about the lens laws here.
Relatedly the thyme package (really fast time implementation) provides lenses for all its data types: http://hackage.haskell.org/package/thyme

Hi,
In a game I made recently, I had to load OBJ formatted models into an
OpenGL-friendly format. To do that, I'd parse the .obj, into a simple ADT,
and build the model into a vector. Here's where lens comes in: we want to
build separate vectors for the vertices, normals, UVs and faces indices.
lens made that very easy, in conjunction with the state monad. Unlike
normal record fields, you can actually pass around lenses freely.
data ModelBuilder = ModelBuilder { _mbVertices, _mbNormals, _mbUvs ::
[Vector Float], ... }
makeFields ''ModelBuilder
addTo label a = label %= (++ Vector.fromList a)
which would be used like:
case objCommand of
V x y z -> addTo vertices [x,y,z]
VN x y z -> addTo normals [x,y,z]
VT x y z -> addTo uvs [x,y,z]
...
I hope to actually release the game that uses this soon -- it's one of the
very few 'complete' 3D games written in Haskell -- when I have the time,
which will probably be around november.
- Mike
On Thu, Oct 3, 2013 at 6:07 PM, Simon Peyton-Jones
(I sent this to ‘libraries’ but Kim-Ee suggested adding Café, where so many smart people hang out.)****
** **
Friends****
** **
Some of you will know that I’ve promised to give a talk about Edward’s lens library http://hackage.haskell.org/package/lens at the Haskell Exchange http://skillsmatter.com/event/scala/haskell-exchange in London next Wednesday (9th). I did this to give everyone (including me) a break from GHC hackery, and also to force me to learn about this lens voodoo that everyone is twittering about. Edward generously gave me quite a bit of one-to-one attention last week (my hair is still standing on end), but this message is to ask your help too.****
*Specifically, I’d like to give some compelling use-cases*. If you are using the lens library yourself, could you spare a few minutes to tell me how you are using it? I expect to cover Lens and Traversal but not Prism. ****
** **
The use-case everyone starts with is nested records, but I’d like to go beyond that. The next levels seem to be:****
**· **Lenses as views of data that isn’t “really there” e.g. regarding a record with rectangular coordinates as having polar coordinates too.****
**· **Lenses and Traversals that focus on elements of finite maps (Control.Lens.At)****
** **
What else? I’m sure you are using them in all sorts of cool ways that I would never think of, and I’d love to know.****
** **
Please don’t tell me anything secret! To give everyone the benefit I may just concatenate all the replies and send to you all, so please say if you don’t want me to do that with yours. ****
** **
And don’t burn too many cycles on this...I don’t want to waste your time, and I can always get back to you if I can’t understand what you say. Sooner is better than later...Weds is coming.****
** **
Simon “Edward’s prophet” PJ****
** **
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Simon,
I've used lenses to manipulate URIs represented as strings in a structured way, like:
modify (port . iso parsePrintUri) (+10) "http://localhost:8070/index.html"
Of course using fclabels and not lens ;-)
Sebastiaan
On Oct 3, 2013, at 10:07 AM, Simon Peyton-Jones
(I sent this to ‘libraries’ but Kim-Ee suggested adding Café, where so many smart people hang out.)
Friends
Some of you will know that I’ve promised to give a talk about Edward’s lens library at the Haskell Exchange in London next Wednesday (9th). I did this to give everyone (including me) a break from GHC hackery, and also to force me to learn about this lens voodoo that everyone is twittering about. Edward generously gave me quite a bit of one-to-one attention last week (my hair is still standing on end), but this message is to ask your help too.
Specifically, I’d like to give some compelling use-cases. If you are using the lens library yourself, could you spare a few minutes to tell me how you are using it? I expect to cover Lens and Traversal but not Prism.
The use-case everyone starts with is nested records, but I’d like to go beyond that. The next levels seem to be: · Lenses as views of data that isn’t “really there” e.g. regarding a record with rectangular coordinates as having polar coordinates too. · Lenses and Traversals that focus on elements of finite maps (Control.Lens.At)
What else? I’m sure you are using them in all sorts of cool ways that I would never think of, and I’d love to know.
Please don’t tell me anything secret! To give everyone the benefit I may just concatenate all the replies and send to you all, so please say if you don’t want me to do that with yours.
And don’t burn too many cycles on this...I don’t want to waste your time, and I can always get back to you if I can’t understand what you say. Sooner is better than later...Weds is coming.
Simon “Edward’s prophet” PJ
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Simon, http://hackage.haskell.org/package/lens-datetime-0.2/docs/Data-Time-Lens.htm... Read the top of the page. aDay = fromGregorian 2013 08 22 aLocal = LocalTime aDay (TimeOfDay 13 45 28) aUTC = UTCTime aDay 7458.9
aLocal ^. years 2013 aUTC ^. months 8 aDay ^. days 22 aLocal & time .~ midnight 2013-08-22 00:00:00 aUTC & days .~ 1 & months .~ 1 2013-01-01 02:04:18.9 UTC aLocal & hours +~ 1 -- But see the note below! 2013-08-22 14:45:28 aLocal & flexDT.months +~ 12 2014-08-22 13:45:28 aUTC & flexDT.days +~ 100 2013-11-30 02:04:18.9 UTC aLocal & flexDT.minutes +~ 120 2013-08-22 15:45:28
Gergely

Lenses for nested sum types e.g. Either.
On 03/10/2013 6:08 PM, "Simon Peyton-Jones"
(I sent this to ‘libraries’ but Kim-Ee suggested adding Café, where so many smart people hang out.)****
** **
Friends****
** **
Some of you will know that I’ve promised to give a talk about Edward’s lens library http://hackage.haskell.org/package/lens at the Haskell Exchange http://skillsmatter.com/event/scala/haskell-exchange in London next Wednesday (9th). I did this to give everyone (including me) a break from GHC hackery, and also to force me to learn about this lens voodoo that everyone is twittering about. Edward generously gave me quite a bit of one-to-one attention last week (my hair is still standing on end), but this message is to ask your help too.****
*Specifically, I’d like to give some compelling use-cases*. If you are using the lens library yourself, could you spare a few minutes to tell me how you are using it? I expect to cover Lens and Traversal but not Prism. ****
** **
The use-case everyone starts with is nested records, but I’d like to go beyond that. The next levels seem to be:****
**· **Lenses as views of data that isn’t “really there” e.g. regarding a record with rectangular coordinates as having polar coordinates too.****
**· **Lenses and Traversals that focus on elements of finite maps (Control.Lens.At)****
** **
What else? I’m sure you are using them in all sorts of cool ways that I would never think of, and I’d love to know.****
** **
Please don’t tell me anything secret! To give everyone the benefit I may just concatenate all the replies and send to you all, so please say if you don’t want me to do that with yours. ****
** **
And don’t burn too many cycles on this...I don’t want to waste your time, and I can always get back to you if I can’t understand what you say. Sooner is better than later...Weds is coming.****
** **
Simon “Edward’s prophet” PJ****
** **
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Lenses for nested ... types ...
Hi Simon/Edward/all, The most compelling uses I've seen for lenses is back to Benjamin Pierce's [et al] papers on "Updatable Views". I think this is where the 'theory' started(?), although similar ideas had kicked around the relational database world for some time. So, a trivial example of that would be treating co-ordinates as simultaneously polar and cartesian. This connects to Wadlers paper on Views, which became Haskell's view patterns. I guess, though, that in a short talk, Simon won't have time to dig into all that history. I see that many of the suggestions in response to Simon have talked about deeply nested structures. (Including for JSON and XML so-called databases.) Now certainly there are applications for nested data, where the topic involves hierarchies. I can see that for AST's and (E)DSL's, organic molecules, exploring a game tree, ... nesting is the natural structure. Given that you have a nested structure, lenses are a really neat approach. I'm going to offer a contrary view: lenses are a solution to a problem that never should have happened. A problem I'd characterise as 'Unnecessary Complexity' [per Fred Brooks]. The data processing industry abandon hierarchical databases in the '80's, because the relational model is so superior. In ten years time, I expect that XML-socalled databases will be regarded as a similar aberration. One of the reasons is redundancy: XML so-called databases repeat field content all over the place. And that's going to give update anomalies: change some of those places, but fail to change all of them. Now formally, hierarchical and relational data models can be made isomorphic. So I'm not criticising the ability to capture data. I am criticising the ease of access (for fetch and update). You end up with your code for the 'business logic' getting muddled in with the code for navigating the hierarchy, making both very brittle to maintain. Given that nested data gives you (especially) an update headache, lenses help you. But a better solution is to do the data analysis up front, apply standard normalisation techniques, and deal with 'flat' data models. And for flat data models, I don't see lenses having any advantages over old-fashioned records. (But! We do need to solve the Field names problem. It's great that Adam's GSOC work has incorporated lenses.) AntC
participants (9)
-
AntC
-
Christopher Done
-
Gergely Risko
-
Mike Ledger
-
Niklas Haas
-
Roman Cheplyaka
-
Sebastiaan Visser
-
Simon Peyton-Jones
-
Tony Morris