From 97711ff04a9f3d76df1bfb9ada454cd170265fc1 Mon Sep 17 00:00:00 2001 From: Sorawee Porncharoenwase Date: Fri, 10 Nov 2023 09:44:29 -0800 Subject: [PATCH] doc: add a margin note to show that (andmap string ...) works This is a follow up of #1345. Thanks to @capfredf for the improvement suggestion. --- .../typed-racket/scribblings/guide/occurrence.scrbl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/typed-racket-doc/typed-racket/scribblings/guide/occurrence.scrbl b/typed-racket-doc/typed-racket/scribblings/guide/occurrence.scrbl index e3f728b94..f50584b79 100644 --- a/typed-racket-doc/typed-racket/scribblings/guide/occurrence.scrbl +++ b/typed-racket-doc/typed-racket/scribblings/guide/occurrence.scrbl @@ -101,7 +101,7 @@ Intuitively, a value that satisfies the predicate must have type (andmap string? lst)) ] -We then may wish to use this predicate to narrow a type in our main program: +We then may wish to use this predicate to narrow a type in the @racket[main] function: @examples[#:label #f #:eval the-eval* (: main (-> (Listof Any) String)) @@ -112,8 +112,13 @@ We then may wish to use this predicate to narrow a type in our main program: ] Unfortunately, Typed Racket fails to narrow the type, because we did not specify -a proposition for @racket[listof-string?]. To fix this issue, we include -the proposition in the @racket[->] form for @racket[listof-string]. +a proposition for @racket[listof-string?].@margin-note*{ + Note that if we directly use @racket[(andmap string? lst)] as the conditional expression, + @racket[main] would be successfully type-checked, + because @racket[andmap] and @racket[string?] do provide propositions + that allow Typed Racket to narrow the type. +} To fix this issue, we include +the proposition in the @racket[->] form for @racket[listof-string?]. @examples[#:no-result #:eval the-eval (: listof-string? (-> (Listof Any) Boolean : (Listof String))) @@ -121,7 +126,7 @@ the proposition in the @racket[->] form for @racket[listof-string]. (andmap string? lst)) ] -With the proposition, Typed Racket successfully type-checks our main program. +With the proposition, Typed Racket successfully type-checks @racket[main]. @examples[#:label #f #:eval the-eval (: main (-> (Listof Any) String))