gluon icon indicating copy to clipboard operation
gluon copied to clipboard

Basic lenses and a macro for deriving them.

Open bch29 opened this issue 4 years ago • 0 comments

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.

bch29 avatar Dec 15 '20 14:12 bch29