<div>I'd like to create a Lens structure which is a procedure structure. The structures exec procedure would be a case-lambda parameterized by A, B.</div><div><br></div><div>(define-struct/exec: (A B) Lens ([getter : (A -> B)][setter : (B A -> A)]) [fn : (case-> (A -> B) (B A -> A))])</div>
<div><br></div><div>where fn would be the getter and setter detemined by arity at the call site.</div><div><br></div><div>Looks like currently a define-struct/exec: cannot be parameterized. Is this something that might be available down the road?</div>
<div><br></div><div>The goal is to say</div><div><br></div><div>(int-lens 3 (int-lens 2))</div><div><br></div><div>as opposed to say</div><div><br></div><div>(set int-lens 3 (get int-lens 2))</div><div><br></div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div>
<div>;; Below is current effort. Want to do a define-struct/exec</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div><br></div><div>(struct: (A B) Lens ([getter : (A -> B)]</div>
<div> [setter : (B A -> A)]))</div><div><br></div><div>(: get (All (A B) (Lens A B) A -> B))</div><div>(define (get lens a)</div><div> ((Lens-getter lens) a))</div><div><br></div><div>(: set (All (A B) (Lens A B) B A -> A))</div>
<div>(define (set lens b a)</div><div> ((Lens-setter lens) b a))</div><div><br></div><div>(: mod (All (A B) (Lens A B) (B -> B) A -> A))</div><div>(define (mod lens f a)</div><div> (set lens (f (get lens a)) a))</div>
<div><br></div><div>(: and-then (All (A B C) (Lens A B) (Lens B C) -> (Lens A C)))</div><div>(define (and-then lens-ab lens-bc)</div><div> (Lens (ė: ((a : A))</div><div> ((Lens-getter lens-bc) ((Lens-getter lens-ab) a)))</div>
<div> (ė: ((c : C) (a : A))</div><div> (mod lens-ab (ė: ((b : B)) ((Lens-setter lens-bc) c b)) a))))</div><div> </div><div>(: compose (All (A B C) (Lens B C) (Lens A B) -> (Lens A C)))</div><div>
(define (compose lens-ab lens-ca)</div><div> (and-then lens-ca lens-ab))</div><div> </div>