Skip to content

Struct inheritence and lenses #290

@LeifAndersen

Description

@LeifAndersen

At the moment, lenses do not seem to compose well with structs that extend other structs. Consider:

#lang racket

(require lens)

(struct/lens foo (a) #:transparent)
(struct bar foo (b) #:transparent)
(define-struct-lenses bar)

(define x (bar 1 20))
(lens-set foo-a-lens x 42) ; (foo 42)

In this example, the resulting lens is a foo, specifically (foo 42), I would like it to still be a bar, in this case (bar 20 42).

I because define-struct-lenses does not try to walk a struct's inheritance chain, I cannot just use bar-a-lens.

Now, I know this is not always possible to do, such as if you don't have an impersonator that does not have access to the struct and if you also do not have access to the struct's fields itself. But if you have access to it, having it walk up the chain and make lenses for it would be very helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions