Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 220
Lubomír Sedlář Avatar asked Feb 14 '15 14:02

Lubomír Sedlář


1 Answers

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.

like image 198
Ben Avatar answered Oct 13 '22 21:10

Ben