From 9aef73b98099971b5f8fb93542a57fd972e0f47b Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Wed, 9 Jun 2010 16:38:07 -0400 Subject: [PATCH] Fix promise printing, add docs. Closes PR 10968. original commit: 0149a05719fdb1fbab56d231905f088bb13b4252 --- .../scribblings/ts-reference.scrbl | 19 +++++++++++++++---- collects/typed-scheme/types/abbrev.rkt | 6 ++++-- collects/typed-scheme/types/printer.rkt | 6 +++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/collects/typed-scheme/scribblings/ts-reference.scrbl b/collects/typed-scheme/scribblings/ts-reference.scrbl index 46f9f993..10cc05e3 100644 --- a/collects/typed-scheme/scribblings/ts-reference.scrbl +++ b/collects/typed-scheme/scribblings/ts-reference.scrbl @@ -167,8 +167,12 @@ The following base types are parameteric in their type arguments. @defform*[[(Parameterof t) (Parameterof s t)]]{A @rtech{parameter} of @racket[t]. If two type arguments are supplied, the first is the type the parameter accepts, and the second is the type returned. -@ex[current-input-port] +@ex[current-input-port + current-directory] } + +@defform[(Promise t)]{A @rtech{promise} of @racket[t]. + @ex[(delay 3)]} @subsection{Other Type Constructors} @@ -184,8 +188,14 @@ The following base types are parameteric in their type arguments. second occurrence of @racket[...] is literal, and @racket[bound] must be an identifier denoting a type variable. In the fourth form, there must be only one @racket[dom] and @racket[pred] is the type - checked by the predicate.} -@defform[(U t ...)]{is the union of the types @racket[t ...]} + checked by the predicate. + + @ex[(λ: ([x : Number]) x) + (λ: ([x : Number] . [y : String *]) (length y)) + ormap + string?]} +@defform[(U t ...)]{is the union of the types @racket[t ...]. + @ex[(λ: ([x : Real])(if (> 0 x) "yes" 'no))]} @defform[(case-lambda fun-ty ...)]{is a function that behaves like all of the @racket[fun-ty]s. The @racket[fun-ty]s must all be function types constructed with @racket[->].} @@ -195,7 +205,8 @@ The following base types are parameteric in their type arguments. type variables @racket[v ...]} @defform[(values t ...)]{is the type of a sequence of multiple values, with types @racket[t ...]. This can only appear as the return type of a -function.} +function. +@ex[(values 1 2 3)]} @defform/none[v]{where @racket[v] is a number, boolean or string, is the singleton type containing only that value} @defform/none[(quote val)]{where @racket[val] is a Racket value, is the singleton type containing only that value} @defform/none[i]{where @racket[i] is an identifier can be a reference to a type diff --git a/collects/typed-scheme/types/abbrev.rkt b/collects/typed-scheme/types/abbrev.rkt index 9bdfbb75..ca9a8995 100644 --- a/collects/typed-scheme/types/abbrev.rkt +++ b/collects/typed-scheme/types/abbrev.rkt @@ -3,7 +3,7 @@ (require "../utils/utils.rkt") (require (rep type-rep object-rep filter-rep rep-utils) - "printer.rkt" "utils.rkt" "resolve.rkt" + #;"printer.rkt" "utils.rkt" "resolve.rkt" (utils tc-utils) scheme/list scheme/match @@ -75,8 +75,10 @@ ;; basic types +(define promise-str (string->uninterned-symbol "Promise")) + (define make-promise-ty - (let ([s (string->uninterned-symbol "Promise")]) + (let ([s promise-str]) (lambda (t) (make-Struct s #f (list t) #f #f #'promise? values (list #'values) #'values)))) diff --git a/collects/typed-scheme/types/printer.rkt b/collects/typed-scheme/types/printer.rkt index e6208201..2c0f959c 100644 --- a/collects/typed-scheme/types/printer.rkt +++ b/collects/typed-scheme/types/printer.rkt @@ -1,7 +1,7 @@ #lang scheme/base (require unstable/sequence racket/require racket/match - (path-up "rep/type-rep.rkt" "rep/filter-rep.rkt" "rep/object-rep.rkt" + (path-up "rep/type-rep.rkt" "rep/filter-rep.rkt" "rep/object-rep.rkt" "types/abbrev.rkt" "rep/rep-utils.rkt" "utils/utils.rkt" "utils/tc-utils.rkt")) ;; do we attempt to find instantiations of polymorphic types to print? @@ -142,8 +142,8 @@ (fp "~a" (cons 'List (tuple-elems t)))] [(Base: n cnt) (fp "~a" n)] [(Opaque: pred _) (fp "(Opaque ~a)" (syntax->datum pred))] - [(Struct: 'Promise par (list fld) proc _ _ _ _ _) (fp "(Promise ~a)" fld)] - [(Struct: nm par flds proc _ _ _ _ _) + [(Struct: (== promise-str eq?) #f (list fld) _ _ _ _ _ _) (fp "(Promise ~a)" fld)] + [(Struct: nm par flds proc _ _ _ _ _) (fp "#(struct:~a ~a" nm flds) (when proc (fp " ~a" proc))