Skip to content

Commit 01e0b82

Browse files
committed
wip
1 parent 5482ed7 commit 01e0b82

File tree

4 files changed

+87
-57
lines changed

4 files changed

+87
-57
lines changed

typed-racket-lib/typed-racket/base-env/base-env.rkt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@
15531553
[system-idle-evt (-> (-evt -Void))]
15541554
[alarm-evt (-> -Real (-mu x (-evt x)))]
15551555
[handle-evt? (asym-pred Univ B (-PS (-is-type 0 (-evt Univ)) -tt))]
1556-
[prop:evt (-struct-property (Un (-evt Univ) (-> -Self ManyUniv) -Nat) #'evt?)]
1556+
[prop:evt (-struct-property (Un (-evt Univ) (-> -Self (-evt Univ)) -Nat) #'evt?)]
15571557
[current-evt-pseudo-random-generator
15581558
(-Param -Pseudo-Random-Generator -Pseudo-Random-Generator)]
15591559

typed-racket-lib/typed-racket/typecheck/tc-structs.rkt

+55-55
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@
458458
(refine-variance! names stys tvarss))
459459

460460

461-
(define ((make-extract check-field-type customized-proc check-doms-rng)
461+
(define ((make-extract check-field-type check-doms-rng error-msg)
462462
ty-stx st-name fld-names desc)
463463
(syntax-parse ty-stx
464464
#:literals (struct-field-index)
@@ -487,45 +487,12 @@
487487

488488
[ty-stx:st-proc-ty^
489489
#:do [(define ty (parse-type #'ty-stx))]
490-
(match ty
491-
[(Fun: (list arrs ...))
492-
(make-Fun
493-
(map (lambda (arr)
494-
(Arrow-update
495-
arr
496-
dom
497-
rng
498-
(lambda (doms rng)
499-
(match (car doms)
500-
[(Name/simple: n)
501-
#:when (free-identifier=? n st-name)
502-
(void)]
503-
[(App: (Name/simple: rator) vars)
504-
#:when (free-identifier=? rator st-name)
505-
(void)]
506-
[(Univ:)
507-
(void)]
508-
[(or (Name/simple: (app syntax-e n)) n)
509-
(tc-error/fields "type mismatch in the first parameter of the function for prop:procedure"
510-
"expected" (syntax-e st-name)
511-
"got" n
512-
#:stx (st-proc-ty-property #'ty-stx))])
513-
(if check-doms-rng
514-
(check-doms-rng #'ty-stx (cdr doms) rng)
515-
(values (cdr doms) rng)))))
516-
arrs))]
517-
[_
518-
(tc-error/fields "type mismatch"
519-
"expected"
520-
"Procedure"
521-
"given"
522-
ty
523-
#:stx #'ty-stx)])]
524-
[_
525-
(customized-proc ty-stx)]))
526-
527-
(define-syntax-rule (define-property-handling-table (name check-field-type custimized-handling rng-chck) ...)
528-
(make-immutable-free-id-table (list (cons name (make-extract check-field-type custimized-handling rng-chck))
490+
(check-doms-rng #'ty-stx ty st-name)
491+
]
492+
[_ (tc-error/stx ty-stx error-msg)]))
493+
494+
(define-syntax-rule (define-property-handling-table (name check-field-type rng-chck error-msg) ...)
495+
(make-immutable-free-id-table (list (cons name (make-extract check-field-type rng-chck error-msg))
529496
...)))
530497

531498
(define property-handling-table
@@ -541,25 +508,58 @@
541508
ty
542509
#:stx ty-stx))
543510
ty)
544-
(lambda (ty-stx)
545-
(tc-error/stx ty-stx
546-
"expected: a nonnegative integer literal or an annotated lambda"))
547-
#f)
548-
(#'prop:evt?
511+
(lambda (ty-stx ty st-name)
512+
(match ty
513+
[(Fun: (list arrs ...))
514+
(make-Fun
515+
(map (lambda (arr)
516+
(Arrow-update
517+
arr
518+
dom
519+
(lambda (doms)
520+
(match (car doms)
521+
[(Name/simple: n)
522+
#:when (free-identifier=? n st-name)
523+
(void)]
524+
[(App: (Name/simple: rator) vars)
525+
#:when (free-identifier=? rator st-name)
526+
(void)]
527+
[(Univ:)
528+
(void)]
529+
[(or (Name/simple: (app syntax-e n)) n)
530+
(tc-error/fields "type mismatch in the first parameter of the function for prop:procedure"
531+
"expected" (syntax-e st-name)
532+
"got" n
533+
#:stx (st-proc-ty-property ty-stx))])
534+
(cdr doms))))
535+
arrs))]
536+
[_
537+
(tc-error/fields "type mismatch"
538+
"expected"
539+
"Procedure"
540+
"given"
541+
ty
542+
#:stx ty-stx)]))
543+
"expected: a nonnegative integer literal or an annotated lambda")
544+
(#'prop:evt
549545
(lambda (ty-stx field-name ty)
550546
(if (Evt? ty)
551547
ty
552548
(make-Evt (Un))))
553-
(lambda (ty-stx)
554-
(tc-error/stx ty-stx
555-
"expected: a nonnegative integer literal, an annotated lambda that returns an event, or an event"))
556-
(lambda (ty-stx doms rng)
557-
(unless (zero? (length doms))
558-
(tc-error/stx ty-stx
559-
"expected: a function that takes only one argument"))
560-
(if (Evt? rng)
561-
(values doms rng)
562-
(values doms (-mu x (make-Evt x))))))))
549+
(lambda (ty-stx ty st-name)
550+
(match ty
551+
[(Fun: (list (Arrow: doms _ _ (Values: (list (Result: rng_t _ _))))))
552+
(unless (= (length doms) 1)
553+
(tc-error/stx ty-stx
554+
"expected: a function that takes only one argument"))
555+
(if (Evt? rng_t)
556+
rng_t
557+
(-mu x (make-Evt x)))]
558+
[_ (if (Evt? ty)
559+
ty
560+
(tc-error/stx ty-stx
561+
"expected: a nonnegative integer literal, an annotated lambda that returns an event, or an event"))]))
562+
"expected: a nonnegative integer literal, an annotated lambda that returns an event, or an event")))
563563

564564

565565

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#lang typed/racket/base
2+
3+
4+
(struct aaa0 ((evt : (Evtof Number)))
5+
#:property prop:evt (struct-field-index evt))
6+
7+
(ann (sync (aaa0 (make-channel))) Number)
8+
9+
10+
(struct aaa1 ([evt : (Evtof Number)])
11+
#:property prop:evt 0)
12+
13+
(ann (sync (aaa1 (make-channel))) Number)
14+
15+
(struct aaa2 ([evt : (Evtof Number)])
16+
#:property prop:evt (lambda ([self : aaa2]) : (Evtof Number)
17+
(aaa2-evt self)))
18+
19+
(ann (sync (aaa2 (make-channel))) Number)
20+
21+
(struct aaa3 ([evt : (Evtof String)])
22+
#:property prop:evt (ann (make-channel) (Evtof String)))
23+
24+
(ann (sync (aaa3 (make-channel))) String)
25+
26+
27+
(struct aaa4 ([evt : (Evtof String)])
28+
#:property prop:evt (make-channel))
29+
30+
(ann (sync (aaa3 (make-channel))) String)

typed-racket-test/succeed/struct-props.rkt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
(lambda ([self : foobar^] [p : Output-Port] [m : (U Boolean 1 0)]) : Void
2929
(displayln (+ (foobar^-y self) 20) p))
3030

31-
#:property prop:evt (make-channel)
31+
#:property prop:evt (ann (make-channel) (Evtof Any))
3232

3333
#:property prop:custom-print-quotable 'self)
3434

0 commit comments

Comments
 (0)