diff --git a/collects/tests/typed-racket/succeed/define-poly-value.rkt b/collects/tests/typed-racket/succeed/define-poly-value.rkt new file mode 100644 index 00000000..c498313e --- /dev/null +++ b/collects/tests/typed-racket/succeed/define-poly-value.rkt @@ -0,0 +1,6 @@ +#lang typed/racket + +;; Test the define: non-function form + +(define: (a) x : (Sequenceof a) empty-sequence) +(define: (a) f : (Integer a -> (Vectorof a)) make-vector) diff --git a/collects/typed-racket/base-env/prims.rkt b/collects/typed-racket/base-env/prims.rkt index 4754d532..57c0a767 100644 --- a/collects/typed-racket/base-env/prims.rkt +++ b/collects/typed-racket/base-env/prims.rkt @@ -370,6 +370,12 @@ This file defines two sorts of primitives. All of them are provided into any mod (identifier? #'nm) (with-syntax ([new-nm (syntax-property #'nm 'type-label #'ty)]) (syntax/loc stx (define new-nm body)))] + [(define: (tvars:id ...) nm:id : ty body) + (with-syntax ([type (syntax/loc #'ty (All (tvars ...) ty))]) + (syntax/loc stx + (begin + (: nm : type) + (define nm body))))] [(define: (tvars:id ...) (nm:id . formals:annotated-formals) : ret-ty body ...) (with-syntax ([type (syntax/loc #'ret-ty (All (tvars ...) (formals.arg-ty ... -> ret-ty)))]) (syntax/loc stx diff --git a/collects/typed-racket/scribblings/reference/special-forms.scrbl b/collects/typed-racket/scribblings/reference/special-forms.scrbl index 87e58ea2..dbceabe3 100644 --- a/collects/typed-racket/scribblings/reference/special-forms.scrbl +++ b/collects/typed-racket/scribblings/reference/special-forms.scrbl @@ -229,11 +229,13 @@ annotations are optional. @defform*[[(define: v : t e) (define: (f . formals) : t . body) + (define: (a ...) v : t e) (define: (a ...) (f . formals) : t . body)]]{ These forms define variables, with annotated types. The first form -defines @racket[v] with type @racket[t] and value @racket[e]. The -second and third forms defines a function @racket[f] with appropriate -types. In most cases, use of @racket[:] is preferred to use of @racket[define:]. +defines @racket[v] with type @racket[t] and value @racket[e]. The third +form does the same, but allows the specification of type variables. +The second and fourth forms defines a function @racket[f] with appropriate +types. In most cases, use of @racket[:] is preferred to use of @racket[define:]. @ex[(define: foo : Integer 10) @@ -241,6 +243,8 @@ types. In most cases, use of @racket[:] is preferred to use of @racket[define:] [rest : Integer]) : Integer (+ first rest)) + (define: (A) mt-seq : (Sequenceof A) empty-sequence) + (define: (A) (poly-app [func : (A A -> A)] [first : A] [rest : A]) : A