Made some type annotations optional in the for: macros.
This commit is contained in:
parent
8b60085a17
commit
9f87b5a7e6
16
collects/tests/typed-scheme/succeed/for-no-anns.rkt
Normal file
16
collects/tests/typed-scheme/succeed/for-no-anns.rkt
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#lang typed/racket
|
||||||
|
|
||||||
|
;; test for optional annotation on for:-bound variables
|
||||||
|
|
||||||
|
(for: ([i (in-range 10)] ; no annotation
|
||||||
|
[j : Integer (in-range 10 20)])
|
||||||
|
(display (+ i j)))
|
||||||
|
|
||||||
|
(for/fold: : Integer ([acc 0])
|
||||||
|
([i (in-range 10)])
|
||||||
|
(+ i acc))
|
||||||
|
|
||||||
|
(let ((x '(1 3 5 7 9)))
|
||||||
|
(do: : Number ((x x (cdr x))
|
||||||
|
(sum 0 (+ sum (car x))))
|
||||||
|
((null? x) sum)))
|
|
@ -14,6 +14,17 @@
|
||||||
#:with ty (syntax-property #'name 'type-label)
|
#:with ty (syntax-property #'name 'type-label)
|
||||||
#:with ann-name #'name))
|
#:with ann-name #'name))
|
||||||
|
|
||||||
|
(define-splicing-syntax-class optionally-annotated-name
|
||||||
|
#:attributes (name ann-name)
|
||||||
|
#:description "optionally type-annotated identifier"
|
||||||
|
#:literals (:)
|
||||||
|
(pattern n:annotated-name
|
||||||
|
#:with name #'n.name
|
||||||
|
#:with ann-name #'n.ann-name)
|
||||||
|
(pattern n:id
|
||||||
|
#:with name #'n
|
||||||
|
#:with ann-name #'n))
|
||||||
|
|
||||||
(define-splicing-syntax-class (param-annotated-name trans)
|
(define-splicing-syntax-class (param-annotated-name trans)
|
||||||
#:attributes (name ty ann-name)
|
#:attributes (name ty ann-name)
|
||||||
#:description "type-annotated identifier"
|
#:description "type-annotated identifier"
|
||||||
|
|
|
@ -9,13 +9,13 @@
|
||||||
|
|
||||||
(define-splicing-syntax-class for-clause
|
(define-splicing-syntax-class for-clause
|
||||||
;; single-valued seq-expr
|
;; single-valued seq-expr
|
||||||
(pattern (~and c (var:annotated-name seq-expr:expr))
|
(pattern (~and c (var:optionally-annotated-name seq-expr:expr))
|
||||||
#:with (expand ...) (list (syntax/loc
|
#:with (expand ...) (list (syntax/loc
|
||||||
#'c
|
#'c
|
||||||
(var.ann-name seq-expr))))
|
(var.ann-name seq-expr))))
|
||||||
;; multi-valued seq-expr
|
;; multi-valued seq-expr
|
||||||
;; currently disabled because it triggers an internal error in the typechecker
|
;; currently disabled because it triggers an internal error in the typechecker
|
||||||
#;(pattern (~and c (((v:annotated-name) ...) seq-expr:expr))
|
#;(pattern (~and c (((v:optionally-annotated-name) ...) seq-expr:expr))
|
||||||
#:with (expand ...) (list (syntax/loc
|
#:with (expand ...) (list (syntax/loc
|
||||||
#'c
|
#'c
|
||||||
((v.ann-name ...) seq-expr))))
|
((v.ann-name ...) seq-expr))))
|
||||||
|
@ -26,14 +26,14 @@
|
||||||
;; intersperses "#:when #t" clauses to emulate the for* variants' semantics
|
;; intersperses "#:when #t" clauses to emulate the for* variants' semantics
|
||||||
(define-splicing-syntax-class for*-clause
|
(define-splicing-syntax-class for*-clause
|
||||||
;; single-valued seq-expr
|
;; single-valued seq-expr
|
||||||
(pattern (~and c (var:annotated-name seq-expr:expr))
|
(pattern (~and c (var:optionally-annotated-name seq-expr:expr))
|
||||||
#:with (expand ...) (list (syntax/loc
|
#:with (expand ...) (list (syntax/loc
|
||||||
#'c
|
#'c
|
||||||
(var.ann-name seq-expr))
|
(var.ann-name seq-expr))
|
||||||
#'#:when #'#t))
|
#'#:when #'#t))
|
||||||
;; multi-valued seq-expr
|
;; multi-valued seq-expr
|
||||||
;; currently disabled because it triggers an internal error in the typechecker
|
;; currently disabled because it triggers an internal error in the typechecker
|
||||||
#;(pattern (~and c (((v:annotated-name) ...) seq-expr:expr))
|
#;(pattern (~and c (((v:optionally-annotated-name) ...) seq-expr:expr))
|
||||||
#:with (expand ...) (list (quasisyntax/loc
|
#:with (expand ...) (list (quasisyntax/loc
|
||||||
#'c
|
#'c
|
||||||
((v.ann-name ...) seq-expr))
|
((v.ann-name ...) seq-expr))
|
||||||
|
|
|
@ -268,7 +268,7 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
||||||
|
|
||||||
(define-syntax (define-typed-struct/exec stx)
|
(define-syntax (define-typed-struct/exec stx)
|
||||||
(syntax-parse stx #:literals (:)
|
(syntax-parse stx #:literals (:)
|
||||||
[(_ nm ((~describe "field specification" [fld:annotated-name]) ...) [proc : proc-ty])
|
[(_ nm ((~describe "field specification" [fld:optionally-annotated-name]) ...) [proc : proc-ty])
|
||||||
(with-syntax*
|
(with-syntax*
|
||||||
([proc* (syntax-property #'(ann proc : proc-ty) 'typechecker:with-type #t)]
|
([proc* (syntax-property #'(ann proc : proc-ty) 'typechecker:with-type #t)]
|
||||||
[d-s (syntax-property (syntax/loc stx (define-struct nm (fld.name ...)
|
[d-s (syntax-property (syntax/loc stx (define-struct nm (fld.name ...)
|
||||||
|
@ -415,7 +415,7 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
||||||
(define-syntax (do: stx)
|
(define-syntax (do: stx)
|
||||||
(syntax-parse stx #:literals (:)
|
(syntax-parse stx #:literals (:)
|
||||||
[(_ : ty
|
[(_ : ty
|
||||||
((var:annotated-name rest ...) ...)
|
((var:optionally-annotated-name rest ...) ...)
|
||||||
(stop?:expr ret ...)
|
(stop?:expr ret ...)
|
||||||
c:expr ...)
|
c:expr ...)
|
||||||
(syntax/loc
|
(syntax/loc
|
||||||
|
@ -452,11 +452,11 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
||||||
;; single-valued seq-expr
|
;; single-valued seq-expr
|
||||||
;; unlike the definitions in for-clauses.rkt, this does not include
|
;; unlike the definitions in for-clauses.rkt, this does not include
|
||||||
;; #:when clauses, which are handled separately here
|
;; #:when clauses, which are handled separately here
|
||||||
(pattern (var:annotated-name seq-expr:expr)
|
(pattern (var:optionally-annotated-name seq-expr:expr)
|
||||||
#:with expand #'(var.ann-name seq-expr))
|
#:with expand #'(var.ann-name seq-expr))
|
||||||
;; multi-valued seq-expr
|
;; multi-valued seq-expr
|
||||||
;; currently disabled because it triggers an internal error in the typechecker
|
;; currently disabled because it triggers an internal error in the typechecker
|
||||||
#;(pattern ((v:annotated-name ...) seq-expr:expr)
|
#;(pattern ((v:optionally-annotated-name ...) seq-expr:expr)
|
||||||
#:with expand #'((v.ann-name ...) seq-expr)))
|
#:with expand #'((v.ann-name ...) seq-expr)))
|
||||||
(syntax-parse clauses
|
(syntax-parse clauses
|
||||||
[(head:for-clause next:for-clause ... #:when rest ...)
|
[(head:for-clause next:for-clause ... #:when rest ...)
|
||||||
|
@ -532,7 +532,7 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
||||||
(define-syntax (for/lists: stx)
|
(define-syntax (for/lists: stx)
|
||||||
(syntax-parse stx #:literals (:)
|
(syntax-parse stx #:literals (:)
|
||||||
[(_ : ty
|
[(_ : ty
|
||||||
((var:annotated-name) ...)
|
((var:optionally-annotated-name) ...)
|
||||||
(clause:for-clause ...)
|
(clause:for-clause ...)
|
||||||
c:expr ...)
|
c:expr ...)
|
||||||
(syntax-property
|
(syntax-property
|
||||||
|
@ -545,7 +545,7 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
||||||
(define-syntax (for/fold: stx)
|
(define-syntax (for/fold: stx)
|
||||||
(syntax-parse stx #:literals (:)
|
(syntax-parse stx #:literals (:)
|
||||||
[(_ : ty
|
[(_ : ty
|
||||||
((var:annotated-name init:expr) ...)
|
((var:optionally-annotated-name init:expr) ...)
|
||||||
(clause:for-clause ...)
|
(clause:for-clause ...)
|
||||||
c:expr ...)
|
c:expr ...)
|
||||||
(syntax-property
|
(syntax-property
|
||||||
|
|
Loading…
Reference in New Issue
Block a user