> First, it's possible that different elements of an array or different properties of an object has different shapes
I can't imagine how this would introduce any sort of difficulties w.r.t. lenses that aren't already present with normal getting and setting of nested structures (aka probably not much).
> Second, it's just difficult to get things right without a compiler's help
This has nothing to do with lenses and everything to do with you preferring the feel of static types. You go on to talk about a bunch of issues with complex constructs that really only exist in static typing.
Sometimes you write a wrong thing and get a runtime error. This happens in all dynamically typed languages (and many statically typed as well).
> Furthermore, without types... this rather elegant unification of getter and setter seems to be lost.
Like ya do. I don't see how this has any impact at all on developing applications.
I'm pretty sure it isn't types that are causing the aesthetic and usability differences you are seeing. I feel the same way about looking at js and typescript lens use. I thought it was just the result of using a concept from one paradigm in a language designed for another, which caused some awkwardness.
This is way beyond what most people need to know to benefit from lens though.
Haskell itself has a counterexample: aeson-lens. It gives you lenses and prisms for working with JSON ASTs. Any unityped language could benefit from lenses for their unityped structures (JS and Clojure come to mind.)
Assuming you are in a unityped context, hkts are gone, functor is not a thing. so
(a -> f a) -> (s -> f s)
is not meaningful. If we pretend that unityped means everything is parametrically polymorphic, for the purpose of this discussion, can't we leverage parametricity to choose a representation that provides this unification?for example, if i provide laws that show for a given
lens :: (s -> a, s -> a -> s)
that (snd lens) s (fst lens $ s) == id s
doesn't that provide the same assurance, even if less elegant and not typechecked (the latter of which is much broader than just applicability of lenses)
* First, it's possible that different elements of an array or different properties of an object has different shapes. I can't imagine how lenses can deal with that in an idiomatic way.
* Second, it's just difficult to get things right without a compiler's help. Forget a `traverse`? Now you are operating nonsense on the wrong level of your nested data structure. Trying to modify an inner structure but you only have a Fold instead of a Traversal? You won't know it won't work without running it to get some cryptic error.
* Furthermore, without types, we obscure the fact that setters and getters are unified: if `a` stands for the part and `s` for the whole, we just have
that is, given a way to transform some inner part, we can transform the whole as well. Getters and setters are just supplying a concrete choice of f, namely the const functor and the identity functor. If we pick f to be the identity functor, then with some unwrapping we have so if there is a function that can modify the part, we have a function that can modify the whole by keeping the rest the same and modify that part. If we pick f to be the const functor, then with some unwrapping we have so if there is a function that can extract the value from the part, we can extract the value from the whole as well. Without types, this rather elegant unification of getter and setter seems to be lost.