3 ms·
I really want to use lenses. The idea of a definition that allows lossless translation from one data representation to another is so elegant. But I wonder if it
by intrepidhero 6y ago
I really want to use lenses. The idea of a definition that allows lossless translation from one data representation to another is so elegant. But I wonder if it's a mathematical ideal that doesn't match up with real world problems? I thought to apply the concept of a lens in my problem domain, converting engineering files to machine readable config files, but the reality is the process is more like combining multiple inputs to form an output, which may not contain all of the input data. So I'm left applying some tricks (including unnecessary data in the output/input) to make the process act like a lens. And it's pretty error prone.
Are there applications for lenses that really allow lossless translation in both directions? Or am I misunderstanding the concept in some fundamental way?
- random3 6y agoWithout being too knowledgeable on the topic, but with a little math background - you'd need a bijective function to that. On a quick search for bijective lenses https://arxiv.org/abs/1710.03248 https://arxiv.org/abs/1710.03248
- pvh 6y agoClose! In math lingo, you can only have a bijective function for domains with equal cardinality. In other words, you couldn't have a bijective function between an integer and a boolean, because there are fewer possible boolean values than integer values. Demanding bijective functions is probably more restrictive than you want to be for building real-world systems. We discuss this a bit in the paper -- I think look for "convert".
- random3 6y agoThank you! I guess in absence of that, the lens is the codomain so to speak so must retain the info. Will read when I get a chance :)
- tengbretson 6y agoThis was my take-away as well. This is cool and all, but if your mapping problem can be entirely solved declaratively like this I don't know if you actually had all that tough of a problem in the first place. Almost every data translation nightmare I've been sucked into involved some pretty sophisticated business logic, and any declarative language that has the sufficient power to handle it inevitably becomes more complicated to write and maintain than a turing-complete, plain old programming language.