Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified documentation example? #61

Open
kurt-mueller-osumc opened this issue Feb 15, 2022 · 1 comment
Open

Simplified documentation example? #61

kurt-mueller-osumc opened this issue Feb 15, 2022 · 1 comment

Comments

@kurt-mueller-osumc
Copy link

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.

@kolektiv
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants