Search code examples
haskellhaskell-lens

What is the purpose of united lens?


While reading through the Lens over Tea #1 article, I found the united lens. My implementation is

united :: Lens' a ()
united f v = const v <$> f ()

which is pretty much the same as the implementation in the Lens library.

What leaves me completely baffled is why would I want a function like this in the first place? Are there any uses of this lens?


Solution

  • I've never actually seen or used this before. But I imagine it's useful in the same way as the id function (which returns it's argument unmodified) or the Identity monad (which is a monad with no "effects"; exactly equivalent to not using monads at all) are useful.

    These and other similar concepts (including the () type!) are basically "do-nothing" structures, so they seem useless when you look at them by themselves. But they become useful when polymorphism is involved, by giving you a "do-nothing" option to pass to general operations.