[racket] TypedRacket Exec Structures
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.
(define-struct/exec: (A B) Lens ([getter : (A -> B)][setter : (B A -> A)])
[fn : (case-> (A -> B) (B A -> A))])
where fn would be the getter and setter detemined by arity at the call site.
Looks like currently a define-struct/exec: cannot be parameterized. Is
this something that might be available down the road?
The goal is to say
(int-lens 3 (int-lens 2))
as opposed to say
(set int-lens 3 (get int-lens 2))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Below is current effort. Want to do a define-struct/exec
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(struct: (A B) Lens ([getter : (A -> B)]
[setter : (B A -> A)]))
(: get (All (A B) (Lens A B) A -> B))
(define (get lens a)
((Lens-getter lens) a))
(: set (All (A B) (Lens A B) B A -> A))
(define (set lens b a)
((Lens-setter lens) b a))
(: mod (All (A B) (Lens A B) (B -> B) A -> A))
(define (mod lens f a)
(set lens (f (get lens a)) a))
(: and-then (All (A B C) (Lens A B) (Lens B C) -> (Lens A C)))
(define (and-then lens-ab lens-bc)
(Lens (λ: ((a : A))
((Lens-getter lens-bc) ((Lens-getter lens-ab) a)))
(λ: ((c : C) (a : A))
(mod lens-ab (λ: ((b : B)) ((Lens-setter lens-bc) c b)) a))))
(: compose (All (A B C) (Lens B C) (Lens A B) -> (Lens A C)))
(define (compose lens-ab lens-ca)
(and-then lens-ca lens-ab))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120602/8a4a8329/attachment.html>