Add define: form variant for polymorphic non-function values
original commit: acda049f7d102bd370d750e524e8fd7638201627
This commit is contained in:
parent
0c509a001f
commit
160d731c4a
|
@ -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)
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user