jackfirth / lens

A Racket package for creating and composing pure functional lenses
Other
73 stars 8 forks source link

struct->vector isomorphism #254

Open jackfirth opened 8 years ago

jackfirth commented 8 years ago

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)
AlexKnauth commented 8 years ago

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.

jackfirth commented 8 years ago

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.

AlexKnauth commented 8 years ago

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.

jackfirth commented 8 years ago

Agreed, that would probably be the best way to do this.

AlexKnauth commented 8 years ago

Should this issue be closed because of https://github.com/jackfirth/lens/pull/266 ?