lens
lens copied to clipboard
struct->vector isomorphism
Given a structure id, it should be possible to construct an isomoprhism between struct instances of that type and vectors
> (struct position (x y))
> (lens-view (struct->vector-lens position) (position 1 2))
'#(1 2)
I think using the name struct->vector-lens would be confusing because struct->vector puts the extra struct:position symbol at the beginning. struct->list-lens would work for this though, because struct->list doesn't include that symbol.
I forgot about struct->vector, the lens form should match whatever that does. A struct->list lens would have to be careful of the fact that struct->list is only available in racket 6.3, I'd like to keep supporting the versions we do now.
We could support struct->list-lens without relying on 6.3 if we looked at the struct-info and used the normal accessors, which we should probably be doing anyway.
Agreed, that would probably be the best way to do this.
Should this issue be closed because of https://github.com/jackfirth/lens/pull/266 ?