xyncro/aether

Simplified documentation example?

kurt-mueller-osumc opened this issue · 1 comments

In the Composition section of the Lenses guide, there's this example:

(* Lens<'a,'b> -> 'a -> 'b *)
let get (g,_) =
    fun a -> g a

(* Lens<'a,'b> -> 'b -> 'a -> 'a *)
let set (_,s) =
    fun b a -> s b a

Could (and should?) this be simplified to:

(* Lens<'a,'b> -> 'a -> 'b *)
let get (g,_) = g

(* Lens<'a,'b> -> 'b -> 'a -> 'a *)
let set (_,s) = s

The latter code snippet is functionally the same as the former. Is there any reason why the first code snippet is used instead of the second? Perhaps I'm missing the point it's trying to make.

You're absolutely right that the code could be simplified in that way - it is just function application after all. Although it's a while ago, I think the reason I wrote it this way was to effectively make that explicit - there's no magic other than normal function application, a lens is simply a pair of functions. And hopefully that fits in well with the progression of building up a lens. It might be good to add your simplification as an aside though, for those who spot it!