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

Basic lenses and a macro for deriving them. #898

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bch29
Copy link

@bch29 bch29 commented Dec 15, 2020

Adds basic lenses to the standard library, along with a macro for deriving lenses for record fields

let lens = import! std.lens

type MyRecord = {
    x: Int,
    y: String
}

let _x = lens! lens MyRecord x
let _y = lens! lens MyRecord y

The main reason I want this in upstream is so that I can use the lens! macro without the gluon language server complaining at me. I chose to implement lenses as a newtype wrapper here. The downside to this is that if this is ever expanded into a proper lens library, these lenses won't be able to compose with other optics. It may be best to just omit the standard library component of this PR altogether. The macro will work if you give it any module containing a make function with the right type.

A caveat of this macro implementation is that it doesn't work with types that have type arguments.

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

Successfully merging this pull request may close these issues.

None yet

1 participant