lens
lens copied to clipboard
Prefab struct -> string isomorphism lens
trafficstars
> (struct posn (x y) #:prefab)
> (define posn->string-lens (prefab-struct-isomorphism-lens posn))
> (lens-view posn->string-lens (posn 1 2))
"#s(posn 1 2)"
> (lens-set posn->string-lens (posn 1 2) "#s(posn 0 0)")
#s(posn 0 0)
Not sure on naming, but this is the general idea. A more general read/write isomorphism would also be worth looking into.
But this would have to recur into the fields, so I think it would require a more general read/write lens anyway, right? Or would prefab-struct-isomorphism-lens take arguments for handling that, for instance like:
(prefab-struct-isomorphism-lens posn number->string-lens number->string-lens)
You're right. I think maybe this should accept lenses for the fields, and a more general read-write isomorphism would be a separate thing altogether. That seems the most natural way to go about it.